In PHP, a multidimensional array is an array that contains one or more arrays as its elements. It allows you to store data in a hierarchical structure. Here is an example of how to use a multidimensional array in PHP:
In the example above, we define a multidimensional array called 'students'. Each element of the 'students' array is an array itself, containing three values - the first name, last name, and age of each student.
To access elements of a multidimensional array, you use square brackets to specify the index of each dimension. In the example above, $students[0][0] accesses the first name of the first student, $students[1][1] accesses the last name of the second student, and $students[2][2] accesses the age of the third student.
You can also loop through a multidimensional array using nested loops:
In the example above, we use a nested foreach loop to loop through each element of the 'students' array and print out each value. The outer loop iterates over each student, while the inner loop iterates over each value in the student's array.
No comments:
Post a Comment