Complete the code to create a 2D array with two rows.
<?php
$matrix = array(
array(1, 2),
[1]
);
print_r($matrix);
?>The second row of the 2D array is created with array(5, 6).
Complete the code to access the element '8' from the 2D array.
<?php
$matrix = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
echo $matrix[1];
?>The element '8' is in the third row (index 2) and second column (index 1), so $matrix[2][1] accesses it.
Fix the error in the code to correctly add a new row to the multidimensional array.
<?php
$matrix = array(
array(1, 2),
array(3, 4)
);
$matrix[] = [1];
print_r($matrix);
?>To add a new row, you must add an array. So array(5, 6) is correct.
Fill both blanks to create a 3x3 matrix with all zeros.
<?php
$matrix = array(
array([1], [2], 0),
array(0, 0, 0),
array(0, 0, 0)
);
print_r($matrix);
?>To create a matrix with all zeros, use 0 for each element.
Fill all three blanks to create an associative multidimensional array representing students and their scores.
<?php
$students = array(
"Alice" => array("Math" => [1], "Science" => [2]),
"Bob" => array("Math" => [3], "Science" => 85)
);
print_r($students);
?>Alice's Math score is 95, Science is 80, and Bob's Math score is 75.
