iterating through a stdClass object in PHP

后端 未结 5 1136
我寻月下人不归
我寻月下人不归 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:39

    function objectToArray( $data ) 
    {
        if ( is_object( $data ) ) 
            $d = get_object_vars( $data );
    }
    

    Convert the Object to array first like:

    $results = objectToArray( $results );
    

    and use

    foreach( $results as result ){... ...}
    

提交回复
热议问题