note 75300 deleted from function.array-pop by tularis
| From: | tularis@php.net | Date: | Fri, 25 May 2007 23:00:30 +0000 |
| Subject: | note 75300 deleted from function.array-pop by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126920@lists.php.net to get a copy of this message | ||
Note Submitter: iain at deletethis dot workingsoftware dot com dot au
----
This is a little function for maintaining keys in all situations:
<?php
function keySafePop(&$array)
{
if(is_array($array)&&count($array))
unset($array[array_search(end($array),$array)]);
}
$one = array('1' => 'this','12' =>
'that','1022' => 'the other');
keySafePop($one);
print_r($one);
$two = array('this' => 'that',2 =>
'element','2-3-1' => 'final');
keySafePop($two);
print_r($two);
$three = array('one','two','three','four');
keySafePop($three);
print_r($three);
?>