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.
1
Syntax: json_encode($array, Constant1 | Constant2 .... | Constantn);
How to log out a user after 10 minutes of inactivity on the site

Consider sample PHP Array
1
2
3
4
5
$array = array(
"website" => "Techiesbadi",
"description" => "Programming Blog"
);
Now we have to convert this array to JSON string.
1
2
3
4
5
6
7
8
9
10
11
12
<?php 
 $array = array
 "website" => "Techiesbadi"
 "url" => "http://techiesbadi.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
1
2
3
4
5
{
    "website": "Techiesbadi",
    "url": "http://techiesbadi.in",
    "description": "Programming Blog"
}
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

Related Posts