Skip to content

Instantly share code, notes, and snippets.

@neatlife
Last active December 12, 2017 14:48
Show Gist options
  • Save neatlife/8cdba218bae94e115381bc39cb825eb6 to your computer and use it in GitHub Desktop.
Save neatlife/8cdba218bae94e115381bc39cb825eb6 to your computer and use it in GitHub Desktop.
php convert object to array
```php
function varDumper($vars)
{
$results = [];
if (is_array($vars)) {
foreach($vars as $key => $var) {
$keyPrefix = '';
if (is_object($var)) {
$keyPrefix = get_class($var);
}
$results[$keyPrefix . ':' . $key] = varDumper($var);
}
} else if (is_object($vars)) {
foreach((array) $vars as $key => $var) {
$results[$key] = varDumper($var);
}
} else {
$results = $vars;
}
return $results;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment