Mixed Array and object

后端 未结 1 1968
情歌与酒
情歌与酒 2021-01-17 04:36

I have an array like this:

Array
(
    [count] => 2
    [0] => stdClass Object
        (
            [term_id] => 3109
            [name] => Alie         


        
1条回答
  •  暖寄归人
    2021-01-17 05:03

    foreach ($array as $key => $value) {
        if (is_object ($value)) echo $value->slug;
    }
    

    It simply loops through the array $array and if the element is an object (so it doesn't try to parse count), it echoes slug.

    0 讨论(0)
提交回复
热议问题