Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[ Posted by Long + ] json test json decode function
<pre>
<?php
$json = '{"a": {"b":"5"}}';
$valueDecodeObject = json_decode($json);
$valueDecodeArray = json_decode($json, true);
echo "<p>Option 1: </p>";
var_dump($valueDecodeObject);
// echo $valueDecodeObject['a']['b']; => error
echo $valueDecodeObject->a->b;
echo "<p>Option 2: </p>";
var_dump($valueDecodeArray);
echo $valueDecodeArray['a']['b'];
// echo $valueDecodeArray->a->b; => error
?>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment