⊗ppSpJnTD 15 of 95 menu

Converting Data from JSON to PHP

Using the function json_decode you can automatically convert data from JSON format to PHP structures. Let's look at an example. Suppose we have the following JSON:

<?php $json = '[1, 2, 3]'; ?>

Let's convert the data to PHP:

<?php $data = json_decode($json); ?>

Let's see what we got:

<?php var_dump($data); // array [1, 2, 3] ?>

Convert the following JSON into a PHP structure:

<?php $json = '[ "x", "y", "z" ]'; ?>
byenru