Heim >Backend-Entwicklung >PHP-Tutorial >PHP数组与对象的相互转换

PHP数组与对象的相互转换

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:55:33964Durchsuche

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 Objectfunction array_to_object($array = array())    {        return (object) $array;    }

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn