What is the purpose of the function object2array() in PHP?
The function object2array() in PHP is used to convert an object into an associative array. This can be useful when you need to work with the data in the object in array format, such as when passing it to functions that expect an array as input.
function object2array($object) {
if (is_object($object)) {
$object = get_object_vars($object);
}
if (is_array($object)) {
return array_map(__FUNCTION__, $object);
} else {
return $object;
}
}