/** * 对象转数组 * @author ffx * @param $obj * @return array|void */ function object2array($obj) { $obj = (array)$obj; foreach ($obj as $k => $v) { if (gettype($v) == 'resource') { return; } if (gettype($v) == 'object' || gettype($v) == 'array') { $obj[$k] = (array)object2array($v); } } return $obj; } /** * 数组转对象 * @param object $obj 对象 * @return array */ function array2object($array) { if (is_array($array)) { $obj = new StdClass(); foreach ($array as $key => $val){ $obj->$key = $val; } } else { $obj = $array; } return $obj; }