Re[2]: [PHP4BETA] count($array,1) or count($array)
[email protected] (Cynic)
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
The tip is wrong.
<?
function uniqueArray($array)
{
// Get unique elts as keys in assoc. array
for ($i=0,$n=count($array, 1);$i<$n;$i++)
$u_array[$array[$i]] = 1;
// Copy keys only into another array
reset($u_array, 1);
for ($i=0,$n=count($u_array, 1);$i<$n;$i++) {
$unduplicated_array[] = key($u_array, 1);
next($u_array, 1);
}
return $unduplicated_array;
}
$x = array( 1 , 1 , 3 , 4 , 4 , 5 ) ;
echo uniqueArray( $x ) ;
?>
results in
Warning: Wrong parameter count for count() in test2.php4 on line 6
Warning: Wrong parameter count for reset() in test2.php4 on line 10
Warning: Wrong parameter count for count() in test2.php4 on line 11
This works as expected:
function uniqueArray($array)
{
// Get unique elts as keys in assoc. array
for ($i=0,$n=count($array);$i<$n;$i++)
$u_array[$array[$i]] = 1;
// Copy keys only into another array
reset($u_array);
for ($i=0,$n=count($u_array);$i<$n;$i++) {
$unduplicated_array[] = key($u_array);
next($u_array);
}
return $unduplicated_array;
}
At 21:36 22.5.2000 -0700, [email protected] wrote the following:
--------------------------------------------------------------
>Hello Cynic,
>
>Monday, May 22, 2000, 5:58:03 AM, you wrote:
>
>C> I don't understand what you ask about. Can you rephrase your
>C> question?
>
>C> --------------------------------------------------------------
> >>Hello ,
> >>
> >> I never see count($array,1) in doc, but someone to use it.
> >> count($array) unlikeness count($array) ??
> >>
> >> Thanks fou you help!
> >>
>
> At http://www.zend.com/tips/tips.php?id=18&single=1 have this code:
>############################################
><?
>function uniqueArray($array)
>{
> // Get unique elts as keys in assoc. array
> for ($i=0,$n=count($array, 1);$i<$n;$i++)
> $u_array[$array[$i]] = 1;
>
> // Copy keys only into another array
> reset($u_array, 1);
> for ($i=0,$n=count($u_array, 1);$i<$n;$i++) {
> $unduplicated_array[] = key($u_array, 1);
> next($u_array, 1);
> }
> return $unduplicated_array;
>}
>?>
>############################################
>
>At php4 doc function count():
>############################################
>count -- count elements in a variable
>Description
>
>int count(mixed var);
>
>Returns the number of elements in var, which is typically an array (since anything else will have one element).
>
>Returns 1 if the variable is not an array.
>
>Returns 0 if the variable is not set.
>###########################################
>
>The "count($u_array, 1)" and "count($u_array)" is what mean ?
>
>I am sorry for my english so poor !
>--
>Best regards,
> php mailto:[email protected]
>
>
>
>--
>PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>To contact the list administrators, e-mail: [email protected]
------end of quote------
____________________________________________________________
Cynic:
A member of a group of ancient Greek philosophers who taught
that virtue constitutes happiness and that self control is
the essential part of virtue.
[email protected]
ICQ: 2808 2505