Voting

: two minus one?
(Example: nine)

The Note You're Voting On

mark
19 years ago
If the property of an object is empty the array is not created. Here is a version object2array that transfers properly.

<?php
function object2array($object)
{
$return = NULL;

if(
is_array($object))
{
foreach(
$object as $key => $value)
$return[$key] = object2array($value);
}
else
{
$var = get_object_vars($object);

if(
$var)
{
foreach(
$var as $key => $value)
$return[$key] = ($key && !$value) ? NULL : object2array($value);
}
else return
$object;
}

return
$return;
}
?>

<< Back to user notes page

To Top