PHP object to array and array to object operations
1. The following is the code to convert an object into an array:
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. The following is the code for converting an array into an object:
public static function array2object($d)
{
if (is_array($d))
return (object) array_map('self::array2object', $d);
else
return $d;
}
http://www.bkjia.com/PHPjc/953330.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953330.htmlTechArticlePHP object to array and array to object operations 1. The following is the code for converting an object to an array: public static function object2array($d){if (is_object($d)) $d = get_object_vars($d);if (i...
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