An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. It is a versatile and fundamental data structure used for organizing, storing, and manipulating data. PHP arrays can hold various types of data, including strings, numbers, and even other arrays.

There are three types of PHP Arrays :
- Indexed arrays
- Associative arrays
- Multidimensional arrays
Indexed arrays
PHP indexed array is an array which is represented by an index number by default. All elements of an array are represented by an index number which starts from 0.indexed array can store numbers.
Code :-
$numericArray = array("Apple", "Banana", "Orange");
// or
$numericArray = ["Apple", "Banana", "Orange"];
// Accessing elements
echo $numericArray[0];
Output
Apple
Associative arrays
An associative array is created using the array() function with a set of key-value pairs, where each key represents a unique identifier for a value in the array. These keys can be of any data type, including strings, integers, and floats.
Code
$student = array(
"name" => "Yash Agarwal",
"age" => 21,
"stream" => "Computer Science"
);
foreach($student as $key => $value) {
echo $key . ": " . $value . "<br>";
}
Output :-
name: Yash Agarwal
age: 21
stream: Computer Science
Multidimensional arrays
A multi-dimensional array of each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple indexes.
Code
<?php
$marks = array(
"kevin" => array (
"physics" => 95,
"maths" => 90,
),
"ryan" => array (
"physics" => 92,
"maths" => 97,
),
);
echo "Marks for kevin in physics : " ;
echo $marks['kevin']['physics'] . "\n";
echo "Marks for ryan in maths : ";
echo $marks['ryan']['maths'] . "\n";
?>
Output
Marks for kevin in physics : 95
Marks for ryan in maths : 97