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