PHP数组转对象,对象转数组
废话不多,直接上代码:
<?php class object_array{ //数组转对象 public static function array_to_object($e){ if(gettype($e)!='array') return; foreach($e as $k=>$v){ if(gettype($v)=='array' || getType($v)=='object') $e[$k]=self::arrayToObject($v); } return (object)$e; } //对象转数组 public static function obj_to_array($e){ $e=(array)$e; foreach($e as $k=>$v){ if(gettype($v)=='resource') return; if(gettype($v)=='object' || gettype($v)=='array') $e[$k]=self:: get_array($v); } return $e; } }