Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created July 17, 2019 16:37
Show Gist options
  • Save phpfiddle/a361ab9fb2375e160ea2abcaa0b051c6 to your computer and use it in GitHub Desktop.
Save phpfiddle/a361ab9fb2375e160ea2abcaa0b051c6 to your computer and use it in GitHub Desktop.
[ Posted by Tommie C ] Convert PHP object to array using JSON methods
<?php
$nested_object = new stdClass;
$nested_object->apple = "apple value";
$nested_object->orange = "orange value";
$nested_object->grape = "grape value";
$nested_object->pear = "pear value";
$array = json_decode(json_encode($nested_object), true);
var_dump($nested_object, "object converted to array using json methods" , $array);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment