2014-07-02 193 views
-1

簡單的問題,我正在努力尋找答案。我有一個數組如下:訪問對象數組中的屬性

$t = wp_get_post_tags($post->ID); 
print_r($t); 

,其結果是:

Array 
(
    [0] => stdClass Object 
     (
      [term_id] => 4 
      [name] => tag2 
      [slug] => tag2 
      [term_group] => 0 
      [term_taxonomy_id] => 4 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 7 
     ) 

    [1] => stdClass Object 
     (
      [term_id] => 7 
      [name] => tag5 
      [slug] => tag5 
      [term_group] => 0 
      [term_taxonomy_id] => 7 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 6 
     ) 

    [2] => stdClass Object 
     (
      [term_id] => 16 
      [name] => tag6 
      [slug] => tag6 
      [term_group] => 0 
      [term_taxonomy_id] => 16 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 2 
     ) 

) 

如何獲得[COUNT]值的值的第一個[0],第二個[1所述陣列中]和第三[2]?

+1

'$ T [0] - > count','$ T [1] - > count','$ T [2] - > count' – Bora

+0

感謝。我一直在尋找解決方案長達1小時。並最終由您解決。 – user3148904

+0

有人會同意標題混淆嗎?我不知道是否應該將它改爲:「訪問一個對象數組中的屬性」,還是那個太激進? – thpl

回答

0

您可以使用此:

<?php 

foreach ($t as $val) { 
    echo $val->count; 
} 

?> 
相關問題