Home  >  Article  >  Backend Development  >  php对象转成数组和数组转成对象操作

php对象转成数组和数组转成对象操作

WBOY
WBOYOriginal
2016-06-23 13:41:511118browse

1.下面是对象转成数组的代码:

public static function object2array($d)	{		if (is_object($d)) $d = get_object_vars($d);		if (is_array($d))			return array_map('self::object2array', $d);		else			return $d;	}

2.下面是数组转成对象的代码:

public static function array2object($d)	{		if (is_array($d))			return (object) array_map('self::array2object', $d);		else			return $d;	}


Statement:
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