Arrays in PHP are used to store multiple values in a single variable. PHP supports both indexed arrays and associative arrays.
An indexed array stores values with a numeric index:
<?php
$fruits = array("Apple", "Banana", "Cherry");
echo $fruits[0]; // Outputs Apple
?>
Associative arrays use named keys to store values:
<?php
$person = array("name" => "John", "age" => 30);
echo $person["name"]; // Outputs John
?>
Create an associative array for a car with keys for "make", "model", and "year". Output the value of the "model" key.
Answers: Indexed arrays use numeric indexes, while associative arrays use named keys. Access values in associative arrays using the key (e.g., $array["key"]
).