Home > Backend Development > PHP Tutorial > PHP数组与对象的相互转换

PHP数组与对象的相互转换

WBOY
Release: 2016-06-13 13:07:08
Original
885 people have browsed it

PHP数组与对象的互相转换
array to object, object to array

// Funcion de Object a Array   
function object_to_array($object)
    {
        if(is_array($object) || is_object($object)){
            $array = array();
            foreach($object as $key => $value){
                $array[$key] = $this->object_to_array($value);
            }
            return $array;
        }
        return $object;
    }

// Funcion de Array a Object
function array_to_object($array = array())
    {
        return (object) $array;
    }
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template