Re: array_pop() with key-value pair ???

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

 



2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta:
> On 16/02/07, Eli <eli.hen@xxxxxxxxx> wrote:
> > Hi,
> >
> > Why isn't there a function that acts like array_pop() returns a pair of
> > key-value rather than the value only ?
> >
> > Reason is, that in order to pop the key-value pair, you do:
> > <?php
> > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
> > $arr_keys = array_keys($arr);
> > $key = array_pop($arr_keys);
> > $value = $arr[$key];
> > ?>
> >
> > I benchmarked array_keys() function and it is very slow on big arrays
> > since PHP has to build the array.
> 
> benchmark this:
> 
> end($arr);
> list($key, $value) = each($arr);

array_pop also removes the element from the array so add one more line:
unset($arr[$key]);

greets
Zoltán Németh

> 
> -robin
> 

-- 
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