PHP function of the day: json_encode()

This is the first of 21 posts in my “PHP Function of the day” series.  These are going to be quicker posts, for the most part.  Maybe I should do it with other languages after this? 🙂

For today, let’s look at json_encode().

<?php

$joe = array(“First_Name”=>”Joe”, “Last_Name”=>”Steinbring”, “Website”=>”jws.dev”);

echo ‘The Array: <br />’;

echo $joe;

echo ‘<br /><br />The JSON: <br />’;

echo json_encode($joe);

?>

 

See the output

 

So, What does json_encode() do?  It takes a value of your choosing and encodes it as JSON.

Leave a Reply

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