2011-09-14 220 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;