1// json object.
2 $contents = '{"firstName":"John", "lastName":"Doe"}';
3
4 // Option 1: through the use of an array.
5 $jsonArray = json_decode($contents,true);
6
7 $key = "firstName";
8
9 $firstName = $jsonArray[$key];
10
11
12 // Option 2: through the use of an object.
13 $jsonObj = json_decode($contents);
14
15 $firstName = $jsonObj->$key;
16