Skip to content

Instantly share code, notes, and snippets.

@anver
Created July 29, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anver/36b3900eaa06af67711f38cd3699cada to your computer and use it in GitHub Desktop.
Save anver/36b3900eaa06af67711f38cd3699cada to your computer and use it in GitHub Desktop.
The below code converted the outer most array to object and not the nested arrays.
$object = json_decode(json_encode($array), false);
but this will force all sub elements to objects
$object = json_decode(json_encode($array, JSON_FORCE_OBJECT), false);
I'm pretty sure the solution would be similar when converting from object to array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment