开发者

loop over this array

开发者 https://www.devze.com 2023-04-05 01:04 出处:网络
( [0] => stdClass Object ( [term_id] => 22 [name] => Data Management [slug] => data-management
(
[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
    )

)

And i want to get at the name entry.

I'm trying:

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

but i get开发者_StackOverflow中文版 an error saying Cannot use object of type stdClass as array in....I'm really not sure how I get around it.

Any ideas?


Your row isnt an array, its an object, you should use the proper syntax to get members of objects:

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


just change

echo $row['name'];

to

echo $row->name;
0

精彩评论

暂无评论...
验证码 换一张
取 消