(
[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类型的对象作为数组....我真的不确定我是如何绕过它的。
有什么想法吗?
答案 0 :(得分:7)
您的行不是数组,它是一个对象,您应该使用正确的语法来获取对象的成员:
foreach ($topicArr as $i => $row) {
echo $row->name;
}
答案 1 :(得分:1)
只需更改
echo $row['name'];
到
echo $row->name;