The easiest way to the forehead
$inputArray = array(2, 5, 5, 3 ,2, 10); $outputArray = array(); // вся работа происходит тут foreach($inputArray as $inputArrayItem) { foreach($outputArray as $outputArrayItem) { if($inputArrayItem == $outputArrayItem) { continue 2; } } $outputArray[] = $inputArrayItem; } // это уже вывод итогового результата foreach($outputArray as $output) { echo $output.'<br>'; }
from the docks :
continue takes an optional numeric argument that indicates how many levels of nested loops the rest of the iteration will be skipped. The default value is 1, which skips the rest of the current loop.
There is another working method that I looked at in some place, but which I myself do not understand how it works))
$array = array(2, 5, 5, 3 ,2, 10); $unique = array(); foreach($array as $v) isset($k[$v]) || ($k[$v] = 1) && $unique[] = $v; // результат echo '<pre>'; print_r($unique); echo '</pre>';