PHPda 3D massivlarni olish
Uch o'lchovli massivni takrorlash uchun endi uchta ichma-ich tsiklni ishlatish kerak. Faraz qilaylik, bizda quyidagi massiv bor:
<?php
$arr = [
[
['a', 'b'],
['c', 'd'],
],
[
['e', 'f'],
['g', 'h'],
],
[
['i', 'j'],
['k', 'l'],
],
];
?>
Keling, uning barcha elementlarini ekranga chiqaraylik:
<?php
foreach ($arr as $sub) {
foreach ($sub as $subsub) {
foreach ($subsub as $elem) {
echo $elem;
}
}
}
?>
№1
quydagi massiv berilgan:
<?php
$arr = [
[
[1, 2, 3],
[6, 7, 8],
[3, 8, 4],
[6, 7, 9],
],
[
[9, 1, 2],
[4, 5, 6],
],
[
[9, 1, 2],
[4, 5, 6],
[5, 6, 3],
],
];
?>
Ushbu massiv elementlarining yig'indisini topish uchun uchta ichki tsikldan foydalaning.