Let’s see how to convert single-dimension and Multi-dimension Object to Array.
Object:
$chair = new stdClass(); $chair->type = "gaming"; $chair->price = 450; $chair->stuff = "leather"; $chair->color = "Black & Red";
Convert Single dimension object to array.
$chairArray = (array) $chair;
Convert Multi dimensional object to array.
$chairArray = object_to_array($chair); function objectToArray ($object) { if(!is_object($object) && !is_array($object)){ return $object; } return array_map('object_to_array', (array) $object); }