note 75300 added to function.array-pop

From: Date: Wed, 23 May 2007 01:01:14 +0000
Subject: note 75300 added to function.array-pop
Groups: php.notes 
Request: Send a blank email to php-notes+get-126833@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 203.202.10.60 Probable Submitter: 203.214.47.53 ---- Manual Page -- http://www.php.net/manual/en/function.array-pop.php Edit -- https://master.php.net/note/edit/75300 Del: integrated -- https://master.php.net/note/delete/75300/integrated Del: useless -- https://master.php.net/note/delete/75300/useless Del: bad code -- https://master.php.net/note/delete/75300/bad+code Del: spam -- https://master.php.net/note/delete/75300/spam Del: non-english -- https://master.php.net/note/delete/75300/non-english Del: in docs -- https://master.php.net/note/delete/75300/in+docs Del: other reasons-- https://master.php.net/note/delete/75300 Reject -- https://master.php.net/note/reject/75300 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126833) next »