note 92521 added to function.array-unshift

From: Date: Tue, 28 Jul 2009 09:56:30 +0000
Subject: note 92521 added to function.array-unshift
Groups: php.notes 
Request: Send a blank email to php-notes+get-158811@lists.php.net to get a copy of this message
Small addition to the assoc unshift below: only add if the key passed is unique <?php //adds a key/value pair to the beginning of an array without resetting numeric keys function array_unshift_assoc( &$array, $key, $value, $overwrite_key = false ) { //if the key can't overwrite and allready exists return false if (!$overwrite_key && array_key_exists( $key, $array )) return false; array_reverse( $array, true ); $array[$key] = $value; array_reverse( $array, true ); return count( $array ); } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 62.166.221.50 ---- Manual Page -- http://www.php.net/manual/en/function.array-unshift.php Edit -- https://master.php.net/note/edit/92521 Del: integrated -- https://master.php.net/note/delete/92521/integrated Del: useless -- https://master.php.net/note/delete/92521/useless Del: bad code -- https://master.php.net/note/delete/92521/bad+code Del: spam -- https://master.php.net/note/delete/92521/spam Del: non-english -- https://master.php.net/note/delete/92521/non-english Del: in docs -- https://master.php.net/note/delete/92521/in+docs Del: other reasons-- https://master.php.net/note/delete/92521 Reject -- https://master.php.net/note/reject/92521 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158811) next »