php数组和对象相互转换

function arrayToObject($e){
    if( gettype($e)!='array' ) return;
    foreach($e as $k=>$v){
        if( gettype($v)=='array' || getType($v)=='object' )//多维数组
            $e[$k]=(object)arrayToObject($v);
    }
    return (object)$e;
}
 
function objectToArray($e){
    $e=(array)$e;
    foreach($e as $k=>$v){
        if( gettype($v)=='resource' ) return;
        if( gettype($v)=='object' || gettype($v)=='array' )//多级对象
            $e[$k]=(array)objectToArray($v);
    }
    return $e;
}

 

posted @ 2016-07-15 17:20  雨落知音  阅读(1626)  评论(0编辑  收藏  举报