PHP function of the day: json_decode()

For day 6 of 21 in the “PHP Function of the day” series, I’m going to look at json_decode().  You might remember json_encode() from last week.  Where json_encode() encodes data as JSON, json_decode() decodes JSON data.

Let’s take a look.


$data = ‘{“First_Name”:”Joe”,”Last_Name”:”Steinbring”,”Website”:””}’;


echo(‘<br />’);


echo(‘<br />’);

var_dump(json_decode($data, true));



See the output


As you could see, this would be very valuable while fiddling with APIs.  What does the ‘true’ value do?  It returns the value as an associative array instead of just an object.

Leave a Reply

Your email address will not be published. Required fields are marked *