Re: Efficency in looping arrays?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey again :)

Peter Lauri:
> But what if the array  have a unordered keystructure? What your loop do is
> to call the value with key $i, or am I wrong? What if the keys are strings?


$arr= array(1 => "dirk", 'wife' => "iris", 'dog' => "feivel", 'peter' => 
"lauri");
$values= array_values($arr);

for($i= 0, $size= sizeof($values); $i < $size; $i++) {
  echo $values[$i];
}

should work :)



> "Dirk Kredler" <dirk@xxxxxxxxxxxxxxxxx> skrev i meddelandet
> news:200411171348.13856.dirk@xxxxxxxxxxxxxxxxxxxx
>
> > hey :)
> >
> > i use for this reason:
> >
> > for($i= 0, $size= sizeof($arr); $i < $size; $i++) {
> >   echo $arr[$i];
> > }
> >
> > Peter Lauri:
> > > Best groupmember,
> > >
> > > For the moment when I loop an array I use something like this:
> > >
> > > reset($arr);
> > > while($a=each($arr)) {
> > >     echo $a['value'];
> > > }
> > >
> > > But the each() function genereates a array with four elements
>
> (0,1,value,
>
> > > key), I am only interested in the "value".

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux