Similar to regular arrays but in which elements have their own key instead of the usual text index.
![Arrays in PHP. Create, add, change. Code example Arrays in PHP. Create, add, change. Code example open](https://lil-code.com/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif)
Arrays in PHP. Create, add, change. Code example
May 4, 2022
Create associative array:
$user = [ "name" => 'Spike', "surname" => 'Johnson', "age" => 23 ];
Show the element of the array:
echo $user['name'];//Spike
Multilevel array
Example:
$families = [["Tom", "Alice"], ["Bob", "Kate"]]; echo $families[0][0]; //Tom echo $families[0][1]; //Alice echo $families[1][0]; //Bob echo $families[1][1]; //Kate
If you want to output an element of a multilevel Associative array, use:
echo $families[2]['name'];//turn to the second array and look for the element with the key "name";
Functions for working with arrays – https://www.php.net/manual/ref.array.php