php object to array

Solutions on MaxInterview for php object to array by the best coders in the world

showing results for - "php object to array"
Hanna
17 Jan 2019
1//This works best
2$array = json_decode(json_encode($object), true);
Angelo
25 Feb 2016
1//It is verry  easy : just cast object to array
2$array =  (array)$object;
Aarón
04 Sep 2020
1$array = (array) $yourObject;
Noemi
30 Oct 2018
1$person = new stdClass();
2$person->firstName = "Taylor";
3$person->age = 32;
4
5//Convert Single-Dimention Object to array
6$personArray = (array) $person;
7
8//Convert Multi-Dimentional Object to Array
9$personArray = objectToArray($person);
10function objectToArray ($object) {
11    if(!is_object($object) && !is_array($object)){
12    	return $object;
13    }
14    return array_map('objectToArray', (array) $object);
15}
Niklas
09 Nov 2019
1$array = (array) $object;
Ashvini
09 Jan 2020
1<?php 
2class sample { 
3      
4    /* Member variables */
5    var $var1; 
6    var $var2; 
7      
8    function __construct( $par1, $par2 )  
9    { 
10        $this->var1 = $par1; 
11        $this->var2 = $par2; 
12    } 
13} 
14  
15// Creating the object 
16$myObj = new sample(1000, "second"); 
17echo "Before conversion: \n"; 
18var_dump($myObj); 
19  
20// Converting object to associative array 
21$myArray = json_decode(json_encode($myObj), true); 
22echo "After conversion: \n"; 
23var_dump($myArray); 
24?> 
25  
26Output:
27Before conversion: 
28object(sample)#1 (2) {
29  ["var1"]=>
30  int(1000)
31  ["var2"]=>
32  string(6) "second"
33}
34
35After conversion: 
36array(2) {
37  ["var1"]=>
38  int(1000)
39  ["var2"]=>
40  string(6) "second"
41}
queries leading to this page
convert array object to array in laravelconvert std object to array phpconvert object to array blade laravelcast array object to array phpobject to array list in laravelhow to convert an object inside a string to object in phpobjetct to array phplaravel variable to arrayrrom object to array in laravelhow to turn an object into an array phpstdclass object to array phpconvert object to arrays phpphp object to array conversionobjects to array phpobject to array return in phpobject to array using phpobject to array phpstdclass to arrayconvert object to associative array phpdomelement object to array phpphp make object into arrraystd class object to array phpphp turn object to arrayconvert std object to array in phpobjet to array phpphp object to array jsobject to array in laravelobject to array php laravelconvert an object in array phpconvert object to array in laravel controllerphp convert js object to arraylaravel model object to arrayconvert object to array phpconvert object tot array phplaravel model to arrayconvert array of object to array of array phpphp object to array convertobject to array laravelphp cast object to arrayobject to array in phparray object to array in phpphp transform object to arrayphp transform stdclass to arrayconvert object to qarray phphow to convert multidimensional array to object in phptake object to array phpconvert objects inside array to array phpobject to array conversion in phpconvert array contain object into arraylist phpconvert object into array in laravelphp objext to arrayconvert obj to array in phplaravel obejct to arrayhow to object into array in phpconvert object into array laravelphp hoe to convertobect to arrayconvert to array laravelarray object to arrayconvert php object to arraylaravel convert to arraychange multidimensional object in array phptransform a object to associative array phplaravel copy object to arrayobject ot array laravelhow to convert object into array in laravelconvert object in to array phpconvert associative object to array phpconverting object to array laravelconvert stdclass object to array phpphp cast to arraybject to array phpconvert stdclass object to string phpmake object to array phpobject class to array phpforce convert object to array phpconvert stdclass to array phpconvert javascript object to array in phpphp convert a object to an arrayconvert obj to array laravelphp standard object to arraystandard object to array phpconvert object to an array in phpphp obj to arrayobject to array php functionhow to convert php object to arrayconvert stdclass object to arrayphp convert stdclass to arrayconvert multidimensional object to array in phpstandard array to normal arrayphp obj to arrphp objeto to arraycast object to array phplaravel 8 object to array exampleconverting object to array in phpphp convert object into arrayconvert data output to array laravelphp stdclass to arrayhow to convert object into array phpphp turn object into arraystdclass to array phpconvert multidimensional object to array phplaravel to arrayconvert object into array in phplumen object to arrayconvert array of objects to array phpphp convert object string to arraystd class to arrayconvert object of objects to array of objects phpphp from object to arrayobject to array in larvelphp cast object ot arrayobject to array element phpconvert an object to array phpphp change object to arrayconvert object to array phpconvert object ot array in laravel phpphp object toarraystdclass to array laravelstd clss to array in phpcast to array phpobject to array convert in phpobject array to array convert in php php typecast object to arraylaravel turn object to arrayconvert object in array phpto array php objecthow to convert object to array in laravelstring object data to array in php exampleobject convert to array phplaravel convert object to arrayget associuative array out of php objectconvert string object to array phphow to convert array of object to array in phpphp objects to arrayget object and convert to array laravel eloquentobhect to array phpconverter object em array phpconvert to array phpstd object to array phpphp convert object to arrayphp convert obje to arrayobj to array phpphp covert object to arrayphp convert object in arrayphp object to arrayphp std object to arrayphp array from object private remove starphp convert object to array fullconvert object to array in laravel bladephp parse object to arrayhow to convert object to an array phpobject array to array laravelconvery to array phpobject as array phphow to transform an object to an array phpobject 28stdclass 29 to array phpstd obj to array phpphp convert multidimensional object to arrayconvert object to array laravelconvert object to array in laravelphp object stdclass to arrayobject to array convert in laravelstring object to array phpconvert obj to array phpconvert object array to array phplaravel convert object to associative arrayhow to convert inner object into array phphow to convert object to array in phpconvert array object to array phpphp object to arrayconvert object to array php laravelconvert object to array in phpconvert the php object to an array transform object to array phphow convert object to array in phplaravel 8 object to arrayobject to array conversio in laravelconvert a php object into arraylaravel object to arrayobject to array convertor phpphp code fro convert object to array object to array php 3baravel object to arrayphp std object to arrayconvert array to multidimensional array phpphp object collection to arrayconvert object into array phpconvert to array laravel 7array of objects to array phpphp obeject to arraytransform object to associative array hpobjects inside array php to arrayhow to convert object into array in phpobject to arraylist in phpcast object to array laravelchange object to array phpphp class to arrayhow to convert 5bobject object 5d in phpobject convert to array laravelturn object into array phplaravel get to arrayphp stdclass to arrrayphp convert objectconvert an object to an array phphow to convert object to array phpobject to associative array phpphp convert objects to arrayhow to convert an object array to array in laravelphp convert std object to arrayclass to array phpconvert class to array phpphp array of object to array of arrayturn object to array phplaravel convert eloquent object to arrayphp convert obj to arraylaravel array to stdclassobject convert to array in phpphp type casting object to arrayjs object to array phpp c5 a1hp object to arrayobject array to array phpchange object to array in phpconvert class object to array phpphp object to array