Showing posts with label Array to Json. Show all posts
Showing posts with label Array to Json. Show all posts

Tuesday, November 8, 2016

How to convert the PHP Array to JSON String

Hi, In this tutorial, I am going to explain, How to convert the PHP Array to JSON String.

If you want to convert the PHP Array to JSON String use the json_encode().It will convert the PHP Array to JSON String.

Syntax: json_encode($array, Constant1 | Constant2 .... | Constantn);
Consider sample PHP Array

$array = array(
"website" => "TechNoise",
"url" => "http://technoise.info",
"description" => "Programming Blog"
);
Now we have to convert this array to JSON string.

<?php  
$array = array(
"website" => "TechNoise",
"url" => "http://technoise.in",
"description" => "Programming Blog"
);
//json_encode($array);
$JSON=json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo "<pre>";
echo $JSON;
echo "</pre>";
?>
Output
{
"website": "technoise",
"url": "http://technoise.in",
"description": "Programming Blog"
}
 
* If you like this post please don’t forget to subscribe Technoise - programming blog for more useful stuff
Share:

Popular Posts

Blog Archive