Skip to content

Instantly share code, notes, and snippets.

@tihoho
Created July 17, 2017 13:44
Show Gist options
  • Save tihoho/f6e4dd9b77ebd27aa13e551ffddbc810 to your computer and use it in GitHub Desktop.
Save tihoho/f6e4dd9b77ebd27aa13e551ffddbc810 to your computer and use it in GitHub Desktop.
<?php
function matrix($x = 3, $y = 3) {
$_matrix = [];
for($_x = 0; $_x < $x; $_x++) {
for($_y = 0; $_y < $y; $_y++) {
$_matrix[$_x][$_y] = mt_rand(1,5);
}
}
return $_matrix;
}
function uniqMulti($arr) {
$uniqs = [];
foreach($arr as $row) {
foreach($row as $key => $val) {
if(!in_array($val, $uniqs)) {
$uniqs[] = $val;
}
}
}
return $uniqs;
}
$matrix = matrix();
// матрица
print_r($matrix);
// уникальные значения
print_r(uniqMulti($matrix));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment