PHP JSON

PHP allows us to encode and decode JSON by the help of json_encode() and json_decode functions.

1) PHP json_encode

The 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 1

Let’s see the example to encode JSON.

 

Output

PHP json_encode example 2

Let’s see the example to encode JSON.

Output

2) PHP json_decode

The json_decode() function decodes the JSON string. In other words, it converts JSON string into a PHP variable.

Syntax:

 

PHP json_decode example 1

Let’s see the example to decode JSON string.

Output

PHP json_decode example 2

Let’s see the example to decode JSON string.

Output

Spread the love

Leave a Reply

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