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 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 | 12780 | en | https://en.ans.wiki/83/how-to-convert-php-arrays-to-json | 8 |