php convert object to array

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

showing results for - "php convert object to array"
Michela
19 Oct 2016
1//This works best
2$array = json_decode(json_encode($object), true);
Valery
19 Feb 2016
1//It is verry  easy : just cast object to array
2$array =  (array)$object;
Tommaso
27 Oct 2019
1$array = (array) $yourObject;
Erika
19 Aug 2019
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}
Charlotte
08 Apr 2016
1// It will work Perfectly Fine.
2$arr = json_decode(json_encode($obj), true);
Eliott
19 Mar 2016
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 class to array phpphp type casting object to arrayphp convert objects to arrayhow to transform an object to an array phpparse objecto to array phpstd class object to array phpmultidimensional array to object phpphp hoe to convertobect to arrayphp convert stdclass to arrayconvert objects inside array to array phplaravel to arrayphp convert object to arrayclass to array phpphp object to array convertlaravel variable to arrayconvert object to array phpphp typecast object to arrayturn object into array phparray of object to array of array phpstd class to arraystdclass to array phpphp convert object string to arrayphp stdclass to arrayconvert list object to array phpconvert object to array in laravel controllerconvert object to array php laravelget associuative array out of php objectcast object to array laravelconvert object to an array in phpphp array of object to array of arrayhow to turn an object into an array phpobject to normal array in laravelstandard array to normal arrayphp obj to arrconvert array object to array phplaravel 8 object to array examplephp from object to arrayhow to convert object into array in laravellaravel convert object to arrayphp object class to arrayphp class object to arrayphp convert object into arrayhow to convert inner object into array phpphp object to array doctirnephp convert objectobjecto to array phpconvert object to associative array phpobject to array convert in phpconvert object to array in phpchange object to array in phpphp 2b object to arraydomelement object to array php 3baravel object to arrayobject to array in phpobject convert to array laravellaravel 8 object to arrayconvert array contain object into arraylist phphow to convert multidimensional array to object in phpconverter object em array phpphp class to arraylaravel get to arrayconvert array of objects to array phpparse php object to arraylaravel object array to arrayconvert object to array in laravel bladecast array object to array phpphp object toarraylaravel model object to arrayphp cast object ot arrayconvert object of objects to array of objects phpconvert associative object to array phphow to object into array in phpconverting object to array in phpstring object data to array in php exampleconvert obj to array phpphp convert obje to arrayconvert object tot array phpphp object to arrayphp parse object ot arrayobject to array list in laravelphp object to arrayarray object to arrayconvert object array to array phpto array php objectstdclass to arrayobjet to array phpconvert obj to array in phpobhect to array phpphp covert object to arrayhow to convert object to array in phpphp cast object to arraycast object to array phphow to convert object to array in laravelobject to array phpobject to array conversio in laravelobject class to array phpobjects inside array php to arraytransform object to associative array hpconvert object into array laravel object to array phpconvert object into array in laravellaravel 8 convert array objectphp transform object to arraylaravel convert to arrayobject to array in laravelmake object to array phpobj to array in phpchange multidimensional object in array phpconvert object in to array phpget object and convert to array laravel eloquentphp object to array conversionlaravel convert object to associative arrayphp object to array jsconvert stdclass object to string phpphp change object to arrayhow to convert object into array in phpconvert array of object to array of array phpbject to array phpphp std object to arrayphp list of objects to arrayconverting object to array laravelhow convert object to array in phpconvert stdclass object to array phpphp convert object in arrayconvert object into array phptake object to array phpconvert php object to arrayphp obeject to arrayphp turn object into arrayphp object to arryconvert object into array in phpobject to array laravellaravel convert eloquent object to arrayconvert javascript object to array in phpconvert an object to an array phpobject to associative array phpconvert php object to array in javascriptobject array to array laravelconvert object to qarray phphow to convert object into array phpconvert object to arrays phplaravel obejct to arrayobject ot array laravelconvery to array phpphp parse object to arraymultidimensional object to one dimensional phpconvert object of array to array phpobjetct to array phpconvert the php object to an array php object stdclass to arrayconvert an object to array phpconvert array object to array in laravelconvert object to array laravelobject array to array phpphp convert to object arrayconvert to array phphow to convert array of object to array in phpconvert object to array in laravelarray object to value phphow to convert object to an array phpconvert obj to array laravelobject to an array in laravelphp code fro convert object to arrayphp standard object to arrayconvert class object to array phpphp stdclass to arrrayphp objeto to arrayphp turn object to arrayconvert stdclass to array phpphp make object into arrrayconvert stdclass object to arrayconvert std object to array phphow to convert an object inside a string to object in phpobject to arraylist in phphow to convert object to array phpconvert object inside array to array phpphp convert js object to arraychange object to array phparray object to array in phpphp convert object to array fullstd obj to array phpconvert data output to array laravelobject to array php functionconvert object in array phparray of objects to array phpstdclass to array laravelconvert string object to array phpobject to array convert in laravelconvert multidimensional object to array in phpconvert to array laravelobject to array return in phpobject as array phphow to convert 5bobject object 5d in phprrom object to array in laravelmysql object to array phpconvert object to array blade laravelphp obj to arraylaravel copy object to arrayconvert object ro array phpobjects to array phpconvert multidimensional object to array phpconvert a php object into arrayobject to array convertor phplaravel convert stdclass to arrayconvert value to array object laravel controllerobject 28stdclass 29 to array phptransform object to array phphow to convert an object array to array in laravellaravel array to stdclasslaravel object to arrayphp std object to arrayphp objects to arrayconvert an object in array phpphp object collection to arrayphp array from object private remove starobject to array in larveljs object to array phpphp convert obj to arraystd clss to array in phpobject to array element phpp c5 a1hp object to arrayconvert array to multidimensional array phplaravel model to arrayphp convert std object to arrayhow to convert php object to arrayphp convert multidimensional object to arrayconvert object to array phpstdclass object to array phplaravel get 28 29 to arrayphp objext to arrayconvert object ot array in laravel phpobject convert to array phpobject array to array convert in php convert to array laravel 7php cast to arrayhow to convert an object of php to an arrayforce convert object to array phptransform a object to associative array phpphp onj to arrayhow to array object laravellaravel turn object to arrayobject to array using phpobject to array conversion in phplumen object to arrayobj to array phpstring object to array phpphp transform stdclass to arraystandard object to array phpstd object to array phpobject convert to array in phpobject to array php laravelphp convert object to array