iterating through a stdClass object in PHP

后端 未结 5 1135
我寻月下人不归
我寻月下人不归 2020-12-03 14:04

I have an object like this:

stdClass Object
(
    [_count] => 10
    [_start] => 0
    [_total] => 37
    [values] => Array
        (
                    


        
5条回答
  •  旧时难觅i
    2020-12-03 14:45

    Since this is the top result in Google if you search for iterate over stdclass it may be helpful to answer the question in the title:

    You can iterate overa stdclass simply by using foreach:

    $user = new \stdClass();
    $user->flag = 'red';
    
    foreach ($user as $key => $value) {
       // $key is `flag`
       // $value is `red`
    }
    

提交回复
热议问题