iterating through a stdClass object in PHP

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

I have an object like this:

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


        
5条回答
  •  心在旅途
    2020-12-03 14:56

    I know it's an old post , but for sake of others: when working with stdClass you should use Reflections:

      $obj = new ReflectionObject($object);
    
      $propeties = $obj->getProperties();
    
          foreach($properties as $property) {
            $name = $property->getName();  <-- this is the reflection class
            $value = $object->$name;       <--- $object is your original $object
    
                here you need to handle the result (store in array etc)
    
    
    
            }
    

提交回复
热议问题