php access json key code example
Example 1: read key value json php
$contents = '{"firstName":"John", "lastName":"Doe"}';
$jsonArray = json_decode($contents,true);
$key = "firstName";
$firstName = $jsonArray[$key];
$jsonObj = json_decode($contents);
$firstName = $jsonObj->$key;
Example 2: php access json object
<?php
$someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
$someObject = json_decode($someJSON);
echo $someObject[0]->name;
?>