How does PHP convert an array into JSON data

In PHP, you can use the json_encode() function to convert an array into JSON format data with the syntax “json_encode(array variables,$options)”. The json_encode() function encodes PHP variables in JSON format and returns JSON format data if the conversion is successful or FALSE if the conversion fails.

<!--?</span--> php
header('content-type:text/html; charset=utf-8');
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
var_dump($arr);
Echo "array to JSON format: 
";
$json=json_encode($arr);
echo $json;
var_dump($json);
? >

Leave a Reply

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

en_USEnglish