Converting JSON Objects to Associative Arrays in PHP
You can make JSON objects
convert into associative
arrays in PHP. To do this,
the second parameter of the function json_decode
needs to be set to the value true
.
Let's try. Suppose we have the following JSON:
<?php
$json = '{
"a": 1,
"b": 2,
"c": 3
}';
?>
Let's convert it into a PHP associative array:
<?php
$data = json_decode($json, true);
?>
Let's check what we got:
<?php
var_dump($data); // ['a' => 1, 'b' => 2, 'c' => 3]
?>
Convert the following JSON into a PHP associative array:
<?php
$json = '{
"ru": ["пн", "вт", "ср"],
"en": ["mn", "tu", "wd"]
}';
?>
Display the English name for Tuesday.