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; 
    }
} 

 

posted @ 2018-04-22 17:23  山上小和尚  阅读(413)  评论(0编辑  收藏  举报