What is multidimensional Array with Example ?
In : IMCA Subject : Web Development Using PHPA multidimensional array is just an array of arrays . It helps you store and organize data in more than one dimension — like a list of lists.
2D Array :
<?php
$students = array(
array("John", 20, "A"),
array("Jane", 22, "A+"),
array("Doe", 19, "B")
);
// Accessing elements
echo $students[0][0]; // Output: John
echo "<br>";
echo $students[1][2]; // Output: A+
?>
3D Array :
<?php
$school = array(
"Grade 10" => array(
"Section A" => array("Alice", "Bob"),
"Section B" => array("Charlie", "David")
),
"Grade 11" => array(
"Section A" => array("Eve", "Frank")
)
);
// Accessing values
echo $school["Grade 10"]["Section B"][1]; // Output: David
?>
A multidimensional array is an array that holds other arrays. It's useful when you need to work with data that has more than one level or structure, like tables or groups. You can access its elements using multiple keys or indexes. The most common types are two-dimensional and three-dimensional arrays.