Pre-recorded question

Question #109
How to convert PHP arrays to JSON?
Answer

The PHP function json_encode() returns a string containing the first parameter converted into JSON.


$myArray = array('one' => 1, 'two' => 2, 'three' => 3);
$json = json_encode($myArray);

// Expected output : "{"one":1,"two":2,"three":3}"
echo $json;

If the conversion failed, json_encode() returns false.

3 events in history
Question by Alphonsio 06/17/2020 at 01:16:57 PM
How to convert arrays to JSON in PHP?
Answer by Alphonsio 06/17/2020 at 01:16:41 PM

The PHP function json_encode() returns a string containing the first parameter converted into JSON.


$myArray = array('one' => 1, 'two' => 2, 'three' => 3);
$json = json_encode($myArray);

// Expected output : "{"one":1,"two":2,"three":3}"
echo $json;

If the conversion failed, json_encode() returns false.

Question by Alphonsio 06/17/2020 at 01:11:09 PM
How to convert PHP arrays to JSON?
# ID Query URL Count

Icons proudly provided by Friconix.