note 54861 added to function.array-push

From: Date: Mon, 18 Jul 2005 10:51:09 +0000
Subject: note 54861 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-92104@lists.php.net to get a copy of this message
As someone pointed out the array_push() function returns the count of the array not the key of the new element. As it was the latter function i required i wrote this very simple replacement. function array_push2(&$array,$object,$key=null){ $keys = array_keys($array); rsort($keys); $newkey = ($key==null)?$keys[0]+1:$key; $array[$newkey] = $object; return $newkey; } ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54861 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54861&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54861&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92104) next »