Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created November 21, 2016 08:59
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 phpfiddle/04994650f4b8d6fb39fcfcaab8a375fb to your computer and use it in GitHub Desktop.
Save phpfiddle/04994650f4b8d6fb39fcfcaab8a375fb to your computer and use it in GitHub Desktop.
[ 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