php - Conversion of nested stdclassobject to a double dimensional array -
how convert double
std class object i.e (stdclass object having again stdclass object in it) array?
i have user type; casting converted single object object inside remained same.
data:
array ( [activities] => array ( ) [goals] => stdclass object ( [activeminutes] => 30 [caloriesout] => 3355 [distance] => 8.05 [steps] => 10000 ) [summary] => stdclass object ( [activescore] => -1 [activitycalories] => 1472 [caloriesbmr] => 2074 [caloriesout] => 3308 [distances] => array ( [0] => stdclass object ( [activity] => total [distance] => 8.46 ) [1] => stdclass object ( [activity] => tracker [distance] => 8.46 ) [2] => stdclass object ( [activity] => loggedactivities [distance] => 0 ) [3] => stdclass object ( [activity] => veryactive [distance] => 2.35 ) [4] => stdclass object ( [activity] => moderatelyactive [distance] => 1.63 ) [5] => stdclass object ( [activity] => lightlyactive [distance] => 4.48 ) [6] => stdclass object ( [activity] => sedentaryactive [distance] => 0 ) ) [fairlyactiveminutes] => 32 [lightlyactiveminutes] => 194 [marginalcalories] => 867 [sedentaryminutes] => 1125 [steps] => 11446 [veryactiveminutes] => 31 ) )
this data has stdclass
object inside array how convert array , make on whole double
dimensional array.
i guess have like:
<?php $a = [ 'foo' => (object)[ 'id' => 1, 'name' => 'foo', ], 'bar' => (object)[ 'id' => 2, 'name' => 'bar', 'nested' => (object)['status' => 'ok'], ], ]; var_export($a);
result:
array ( 'foo' => stdclass::__set_state(array( 'id' => 1, 'name' => 'foo', )), 'bar' => stdclass::__set_state(array( 'id' => 2, 'name' => 'bar', 'nested' => stdclass::__set_state(array( 'status' => 'ok', )), )), )
and try receive like:
array ( 'foo' => array ( 'id' => 1, 'name' => 'foo', ), 'bar' => array ( 'id' => 2, 'name' => 'bar', 'nested' => array ( 'status' => 'ok', ), ), )
so best way done - mentioned @mineshpatel use next code:
var_export(json_decode(json_encode($a), true));