php对象/数组互相转换
php对象/数组互相转换php将对象转化为数组:<?php
function object2array($array) {
if(is_object($array)) {
$array = (array)$array;
} if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = object2array($value);
}
}
return $array;
}
?>
PHP将数组转化成对象:<?php
$a = array("a"=>1,"b"=>2,"c"=>3);
$a = (object)$a; //PHP的类型转换
echo $a->a;
?>
页:
[1]