PHP数组转对象,对象转数组

180it 2020-04-05 PM 2037℃ 0条
<?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; 
    }
} 
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP数组转对象,对象转数组