Associative Arrays in PHP
Multidimensional arrays can also be associative, for example, like this:
<?php
$arr = [
'user1' => [
'name' => 'name1',
'age' => 31,
],
'user2' => [
'name' => 'name2',
'age' => 32,
],
];
?>
Let's use this array to display, for example, the name of the second user:
<?php
echo $arr['user2']['name']; // will output 'name2'
?>
Given the following array:
<?php
$arr = [
'boys' => [1 => 'John', 2 => 'Jack', 3 => 'Ryan'],
'girls' => [1 => 'Emma', 2 => 'Lily', 3 => 'Anna'],
];
?>
Using this array, output the name of the first boy and the name of the second girl.
Given the following array:
<?php
$arr = [
'ru' => ['пн', 'вт', 'ср', 'чт', 'пт', 'сб', 'вс'],
'en' => ['mn', 'ts', 'wd', 'th', 'fr', 'st', 'sn'],
];
?>
Using this array, output the English name for Wednesday.
Given the following array:
<?php
$arr = [
[
'name' => 'user1',
'age' => 30,
'salary' => 1000,
],
[
'name' => 'user2',
'age' => 31,
'salary' => 2000,
],
[
'name' => 'user3',
'age' => 32,
'salary' => 3000,
],
];
?>
Using this array, output the sum of the salaries of the first and third user.