👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.
How to convert PHP arrays to JSON?

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.

More