note 12794 modified in function.array-unique by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:51:02 +0000 |
| Subject: | note 12794 modified in function.array-unique by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79794@lists.php.net to get a copy of this message | ||
To unique an array in newer versions of php - i've found this snippet useful:
<?php
// $old[0] = 1
// $old[1] = 1
// $old[2] = 2
// $old[3] = 1
// $old[4] = 2
$new = array();
for($i=0;$i<count($old);++$i){
if(in_array($old[$i], $new) != "true"){
$new[] = $old[$i];
}
}
//$new now contains:
//
//$new[0] = 1
//$new[1] = 2
?>
/mads
--was--
To unique an array in newer versions of php - i've found this snippet useful:
// $old[0] = 1
// $old[1] = 1
// $old[2] = 2
// $old[3] = 1
// $old[4] = 2
$new = array();
for($i=0;$i<count($old);++$i){
if(in_array($old[$i], $new) != "true"){
$new[] = $old[$i];
}
}
//$new now contains:
//
//$new[0] = 1
//$new[1] = 2
/mads
http://php.net/manual/en/function.array-unique.php