Re: array_pop() with key-value pair ???
| From: | Mikey | Date: | Fri, 16 Feb 2007 09:44:58 +0000 |
| Subject: | Re: array_pop() with key-value pair ??? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248950@lists.php.net to get a copy of this message | ||
I guess you have tried foreach?
foreach ($array as $key => $value) {
...
}
Mikey
Eli wrote:
More over.. PHP seems to be quiet slow when dealing with array_shift() array_unshift(), but it is much faster with array_pop() array_push(). I am not familiar with the PHP internals, but why not add a pointer to the start and end of the array? Good word can be said on PHP that accelerated at least count() function.. Maybe I require too much.. PHP is a rapid development scripting language.. not a massive optimized programming language.. :-/ Eli 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. While array_pop() can be acceleraed by the guts of PHP engine. -thanks