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

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

WBOY
Release: 2016-06-23 13:41:51
Original
1171 people have browsed it

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;	}
Copy after login

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

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


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