Multidimensional Arrays
Arrays can contain arrays. Loop with nested foreach, extract a column with array_column and group data by building arrays.
Example
$s = [["Ada", 90], ["Tunde", 72]];
foreach ($s as [$name, $score]) echo "$name: $score\n";
$rows = [["id" => 1, "n" => "a"], ["id" => 2, "n" => "b"]];
print_r(array_column($rows, "n", "id"));
echo count($s), " ", count($s, COUNT_RECURSIVE), "\n";Result
Ada: 90
Tunde: 72
Array
(
[1] => a
[2] => b
)
2 6Exercise
Extract one column.
($rows, "n")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.