Home › PHP Tutorial › PHP JSON
PHP JSON
Exchange data with JavaScript and APIs.
json_encode turns an array or object into JSON text. json_decode($text, true) turns it back into an associative array.
Example code
<?php
$data = ["name" => "Ada", "langs" => ["PHP", "JS"]];
$json = json_encode($data);
echo $json . PHP_EOL;
$back = json_decode($json, true);
echo $back["langs"][1];
?>