Created
July 17, 2017 13:44
-
-
Save tihoho/f6e4dd9b77ebd27aa13e551ffddbc810 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 | |
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