访问对象数组中的属性

时间:2014-07-02 07:41:42

标签: php arrays

我正在努力寻找答案的简单问题。我有一个数组如下:

$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
       )

)

如何在第一个[0],第二个[1]和第三个[2]的数组中得到[COUNT]值的值?

1 个答案:

答案 0 :(得分:0)

您可以使用:

<?php

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

?>