How to convert arrays to JSON in PHP?
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 fails, json_encode() returns false.
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 fails, json_encode() returns false.
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.
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 12094 | en | https://en.ans.wiki/84/how-to-convert-arrays-to-json-in-php | 9 |