note 16597 deleted from function.array-unique by jimw
| From: | jimw@php.net | Date: | Mon, 05 Nov 2001 20:58:19 +0000 |
| Subject: | note 16597 deleted from function.array-unique by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-20494@lists.php.net to get a copy of this message | ||
Here's a little snippet that was useful to me when checking an array of form values that could
not contain the same number more than once.
// check to make sure all numbers submitted are unique
/* if there are duplicate values, array_unique pulls them out. hence, if the number of items
in the unique array is less than the number of items in the original array, there are duplicate
values that need to be corrected. */
reset ($new_place_number_array); /* have to reset when using each() twice in a row */
$count_new_place_number_array = 0;
while(list($thing,$thing2) = each($new_place_number_array)) {
++$count_new_place_number_array;
};
$unique = array_unique ($new_place_number_array);
$count_unique_array = 0;
while(list($key, $val) = each($unique)) {
++$count_unique_array;
};
if ($count_unique_array < $count_new_place_number_array) {
// numbers are not unique; try again
};