php多维数组、对象的转换array2object and object2array
august 4, 2009 – 9:51 pm
function object2array($object) {
if (is_object($object) || is_array($object)) {
foreach ($object as $key => $value) {
print “$key\r\n”;
$array[$key] = $this->object2array($value);
}
}else {
$array = $object;
}
return $array;
}
function array2object($arrgiven){
//create empty class
$objresult=new stdclass();
foreach ($arrlinklist as $key => $value){
//recursive call for multidimensional arrays
if(is_array($value)) $value=array2object($value);
$objresult->{$key}=$value;
}
return $objresult;
}
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号