Re[2]: [PHP4BETA] count($array,1) or count($array)

From: Date: Mon, 22 May 2000 15:34:10 +0000
Subject: Re[2]: [PHP4BETA] count($array,1) or count($array)
References: 1 2 3  Groups: php.version4 
Request: Send a blank email to php-version4+get-15419@lists.php.net to get a copy of this message
oh, and of course, echo uniqueArray( $x ) ; will print "Array". Try var_dump( uniqueArray( $x ) ; instead. At 17:31 22.5.2000 +0200, Cynic wrote the following: -------------------------------------------------------------- >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, php_list@citiz.net 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:php_list@citiz.net > > > > > > > >-- > >PHP 4.0 Beta Mailing List > ><http://www.php.net/version4/> > >To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net > >For additional commands, e-mail: php4beta-help@lists.php.net > >To contact the list administrators, e-mail: php4beta-admin@lists.php.net >------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. > >cynic@mail.cz >ICQ: 2808 2505 > > > > > > >-- >PHP 4.0 Beta Mailing List <http://www.php.net/version4/> >To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net >For additional commands, e-mail: php4beta-help@lists.php.net >To contact the list administrators, e-mail: php4beta-admin@lists.php.net ------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. cynic@mail.cz ICQ: 2808 2505

« previous php.version4 (#15419) next »