Associative arrays
- Associative arrays in PHP are arrays that use named keys instead of numeric indexes.
- This – makes them more expressive and useful when dealing with key-value pairs.
- Associative arrays can be defined using the array() function or the short array syntax [].
// How to create
$person1 = array("first_name" => "John", "last_name" => "Doe"); $person2 = ["first_name" => "Jane", "last_name" => "Smith"];
// Accessing Values
echo $person1["first_name"];
//Looping Through an Associative Array
foreach ($person1 as $key => $value) { echo "$key : $value<br />"; }