Last active
June 29, 2021 08:38
-
-
Save iruslanalexan/b3a0b16677f034838cf17d075a2c0048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
1.Сгенерировать двумерный массив A произвольных чисел размером 10 на 10. | |
2.Сгенерировать массив B из 10 чисел. | |
3.Вывести результат работы в таблицу: переменные массива А: каждая в свою строку/ячейку. | |
4.Пройтись по массиву A и оставить в нем только числа, которые есть в массиве B | |
5.Вывести результат работы в таблицу: первой строкой должен идти массив B выделенный жирным, остальные строки: массива A каждая переменная должна остаться на своем месте без сдвига после фильтрации массивом B. Если переменной не существует, вместо нее вывести текст “Нет”. | |
*/ | |
/* | |
* make empty 10nd array | |
*/ | |
$dictOne = array_fill(0, 10, array_fill(0, 10, 0)); | |
/* | |
* add values 10nd array | |
*/ | |
array_walk($dictOne, function (&$v, $k) use (&$dictOne) { | |
$cnt = count($v); | |
while ($cnt--) { | |
$v[$cnt] = rand(1, 20); | |
} | |
}); | |
$dictTwo = array_map( | |
function ($v) { | |
return $v; | |
}, range(0, 9) | |
); | |
/* | |
* compare array One with Two | |
*/ | |
$dictThree = []; | |
array_walk($dictOne, function (&$v, $k) use (&$dictThree, $dictTwo) { | |
$cnt = count($v); | |
while ($cnt--) { | |
$v[$cnt] = in_array($v[$cnt], $dictTwo) ? $v[$cnt] : 'None'; | |
} | |
}); | |
/* | |
*/ | |
echo "<table>"; | |
echo "<tr>"; | |
foreach ($dictTwo as $key => $element) echo sprintf('<td></b>%s</b></td>', $key); | |
echo "</tr>"; | |
function print_row(&$item) | |
{ | |
echo('<tr>'); | |
array_walk($item, 'print_cell'); | |
echo('</tr>'); | |
} | |
function print_cell(&$item) | |
{ | |
echo('<td>'); | |
echo($item); | |
echo('</td>'); | |
} | |
array_walk($dictOne, 'print_row'); | |
echo "</table>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment