What would be the best solution here? If there are less then a 100 items in $list? And what if there are more then a million?
Example 1:
<?php
foreach($list as $item) {
if(!in_array($item, $array)){
$array[] = $item;
}
}
$this->doSomethingWithThisArray($array);
?>
Example 2:
<?php
foreach($list as $item) {
$array[] = $item;
}
$this->doSomethingWithThisArray(array_unique($array));
?>
Aucun commentaire:
Enregistrer un commentaire