function array_to_object($variable){
if (is_array($variable)){
$object = new StdClass();
foreach ($variable as $key=>$value){
$object->$key = array_to_object($value);
}
return $object;
} else{
return $variable;
}
}
Friday, August 24, 2012
Convert an object to array in PHP using a recursive function
function object_to_array($variable){
if (is_object($variable)){
$array = array();
foreach ($variable as $key=>$value){
$array[$key] = object_to_array($value);
}
return $array;
} else{
return $variable;
}
}
Subscribe to:
Posts (Atom)