array_unique() and count issue
| From: | CGI GUY | Date: | Sat, 18 Aug 2001 07:57:15 +0000 |
| Subject: | array_unique() and count issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-63278@lists.php.net to get a copy of this message | ||
OK, I want to count the number of unique elements in
an array, then print the total. However, both methods
I've tried return "1"; the man pages explain that the
count() function will return 1 if the var is set but
not an array. But if you look at the 2nd method esp.,
I've set an if-else !is_set() alert which doesn't
appear... Either way, it's a 1. Help!
Method 1:
<?
$count =
array_unique(mysql_fetch_array($mysql_result));
$total = count($count);
print($total);
?>
Method 2:
<?
$array = mysql_fetch_array($mysql_result);
$newarray = array_values($array);
if (!is_array($newarray)) {
print("Not an array");
} else {
$count = array_unique($newarray);
foreach($count as $key => $value) {
$count[$key] = $value++;
}
print($value);
}
?>
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/