An associative array is an array where the keys are strings, and the values are either strings or arrays.
The following code creates an associative array with the keys “fruit” and “color”, and the values “apple”, “red”, and “banana”, “yellow”:
$fruits = array(“apple” => “red”, “banana” => “yellow”);
echo $fruits[“fruit”]; // apple
echo $fruits[“color”]; // red
You can also create an associative array with the keys “fruit” and “color” using the array() function:
$fruits = array(“apple” => “red”, “banana” => “yellow”);
echo $fruits[array(“fruit”, “color”)]; // apple => red
echo $fruits[array(“color”, “fruit”)]; // red => apple