Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created June 30, 2013 21:13
Show Gist options
  • Save pippinsplugins/5896919 to your computer and use it in GitHub Desktop.
Save pippinsplugins/5896919 to your computer and use it in GitHub Desktop.
Simple PHP object to array conversion.
If $foo is an object such as:
`
stdClass Object
(
[something] => 279
[something_2] => 1
)
`
You can convert it to an array by simply doing:
$foo = (array) $foo;
Mind blown.
@cklosowski
Copy link

If you have nested objects however, it may not always convert all of the child items to Arrays. For that. I simply just do the following:

$array = json_decode(json_encode($object));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment