2011-09-14 169 views
-1
(
[0] => stdClass Object 
    (
     [term_id] => 22 
     [name] => Data Management 
     [slug] => data-management 
     [term_group] => 0 
     [term_taxonomy_id] => 22 
     [taxonomy] => topic 
     [description] => 
     [parent] => 0 
     [count] => 1 
    ) 

[1] => stdClass Object 
    (
     [term_id] => 24 
     [name] => High Frequency Travel 
     [slug] => high-frequency-travel 
     [term_group] => 0 
     [term_taxonomy_id] => 24 
     [taxonomy] => topic 
     [description] => 
     [parent] => 0 
     [count] => 1 
    ) 

遍历数组

,我想我们就到名项。

我想:

foreach ($topicArr as $i => $row) { 
    echo $row['name']; 
} 

,但我得到一个错误说不能使用类型为stdClass的对象为数组....我真的不知道我周围怎么弄。

任何想法?

回答

7

你的心不是排的阵列,它的一个对象,你应该使用正确的语法来获得对象的成员:

foreach ($topicArr as $i => $row) { 
    echo $row->name; 
} 
1

只是改变

echo $row['name']; 

echo $row->name;