PHP Tutorial
Home
PHP Install Xampp
PHP Syntax & Comments
PHP Variables
PHP Constants
PHP Data Types
PHP Echo & Print
PHP Strings
PHP If...Else...Elseif
PHP Ternary Operator
PHP Loops
PHP Functions
PHP Arrays
PHP GET & POST
PHP Advanced
PHP Date and Time
PHP Include and Require
PHP File Upload
PHP Sessions
PHP Cookies
PHP Send Email
PHP JSON Parsing
PHP MySQL Database
PHP MySQL Introduction
PHP Connect to MySQL
PHP MySQL Create DB
PHP MySQL Create Table
PHP MySQL Insert Data
PHP MySQL Select Data
PHP MySQL Delete Data
PHP MySQL Update Data
PHP MySQL Where
What is JSON
JSON stands for JavaScript Object Notation. JSON is a standard data-interchange format which is quick and easy to parse and generate.
PHP has some built-in functions to handle JSON.
PHP json_encode()
PHP json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation.
Example
<?php // Declare an array $array = array( "name"=>"abc", "email"=>"abc@gmail.com" ); // Use json_encode() function echo json_encode($array); ?>
PHP json_decode()
PHP json_decode() function is used to decode a JSON object into a PHP object or an associative array.
<?php // Declare a json string $json = '{"name":"abc", "email":"abc@gmail.com"}'; // decode a string var_dump(json_decode($json, true)); ?>
PHP Accessing the Decoded Values
<?php $jsonobj = '{"name":"abc","email":"abc@gmail.com"}'; $obj = json_decode($jsonobj); echo $obj->name; echo $obj->email; ?>