1 /** 2 * 数组 转 对象 3 * 4 * @param array $arr 数组 5 * @return object 6 */ 7 function array_to_object($arr) { 8 if (gettype($arr) != 'array') { 9 return; 10 } 11 foreach ($arr as $k => $v) { 12 if (gettype($v) == 'array' || getType($v) == 'object') { 13 $arr[$k] = (object)array_to_object($v); 14 } 15 } 16 17 return (object)$arr; 18 } 19 20 /** 21 * 对象 转 数组 22 * 23 * @param object $obj 对象 24 * @return array 25 */ 26 function object_to_array($obj) { 27 $obj = (array)$obj; 28 foreach ($obj as $k => $v) { 29 if (gettype($v) == 'resource') { 30 return; 31 } 32 if (gettype($v) == 'object' || gettype($v) == 'array') { 33 $obj[$k] = (array)object_to_array($v); 34 } 35 } 36 37 return $obj; 38 }