2014-07-02 197 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; 
} 

?> 
相关问题