PHP JSONPHP allows us to encode and decode JSON by the help of json_encode() and json_decode functions. 1) PHP json_encodeThe json_encode() function returns the JSON representation of a value. In other words, it converts PHP variable (containing array) into JSON. Syntax: PHP json_encode example 1Let's see the example to encode JSON. Output {"a":1,"b":2,"c":3,"d":4,"e":5} PHP json_encode example 2Let's see the example to encode JSON. Output {"firstName":"Rahul","lastName":"Kumar","email":"[email protected]"} 2) PHP json_decodeThe json_decode() function decodes the JSON string. In other words, it converts JSON string into a PHP variable. Syntax: PHP json_decode example 1Let's see the example to decode JSON string. Output array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) } PHP json_decode example 2Let's see the example to decode JSON string. Output array(3) { ["firstName"]=> string(5) "Rahul" ["lastName"]=> string(5) "Kumar" ["email"]=> string(15) "[email protected]" } Next TopicJava JSON Example |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India