Heim >Backend-Entwicklung >PHP-Tutorial >php对象转成数组和数组转成对象操作
1.下面是对象转成数组的代码:
public static function object2array($d) { if (is_object($d)) $d = get_object_vars($d); if (is_array($d)) return array_map('self::object2array', $d); else return $d; }
public static function array2object($d) { if (is_array($d)) return (object) array_map('self::array2object', $d); else return $d; }