Recall & Review
beginner
What is a multidimensional array in PHP?
A multidimensional array is an array that contains one or more arrays inside it. It is like a table or grid where each element can be accessed using multiple keys or indexes.
Click to reveal answer
beginner
How do you access the element 'PHP' in this array?<br>
$arr = [['HTML', 'CSS'], ['JavaScript', 'PHP']];
You access 'PHP' by using two indexes:
$arr[1][1]. The first index selects the second array, and the second index selects the second element inside it.Click to reveal answer
intermediate
How to add a new element 'Python' to the second array in a multidimensional array?
Use
$arr[1][] = 'Python'; to add 'Python' at the end of the second array inside the multidimensional array.Click to reveal answer
beginner
What will
count($arr) return if $arr = [[1,2], [3,4], [5,6]];?It will return 3 because
count() counts the number of elements in the outer array, which has three inner arrays.Click to reveal answer
intermediate
How can you loop through all elements in a multidimensional array?
Use nested
foreach loops: the outer loop goes through each inner array, and the inner loop goes through each element inside those arrays.Click to reveal answer
What does
$arr[0][1] access in a multidimensional array?✗ Incorrect
$arr[0] selects the first inner array, and [1] selects its second element.
How do you add a new inner array to a multidimensional array
$arr?✗ Incorrect
Using $arr[] = [...] adds a new inner array at the end of the outer array.
What will
count($arr, COUNT_RECURSIVE) do?✗ Incorrect
Using COUNT_RECURSIVE counts all elements inside all nested arrays.
Which loop structure is best to iterate over a multidimensional array?
✗ Incorrect
Nested foreach loops let you access each inner array and its elements easily.
What type of data structure is a multidimensional array similar to?
✗ Incorrect
Multidimensional arrays are like tables with rows and columns.
Explain what a multidimensional array is and how you access its elements in PHP.
Think of it like a table with rows and columns.
You got /2 concepts.
Describe how to loop through all elements of a multidimensional array and why nested loops are needed.
Imagine opening each box inside a bigger box.
You got /2 concepts.