Skip to content

Instantly share code, notes, and snippets.

@ogabrielguerra
Last active September 29, 2018 12:02
Show Gist options
  • Save ogabrielguerra/b3f9282dbb78fe8192b89dd093619380 to your computer and use it in GitHub Desktop.
Save ogabrielguerra/b3f9282dbb78fe8192b89dd093619380 to your computer and use it in GitHub Desktop.
A PHP method to convert JSON attributes into object attributes.
function convertJsonToObjAttributes($json){
$keys = array_keys((array)$json);
$jsonSize = count($json);
for( $i=0; $i<$jsonSize; $i++ )
$this->{$keys[$i]} = $json[$keys[$i]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment