note 92863 added to function.array-unshift

From: Date: Wed, 12 Aug 2009 10:44:57 +0000
Subject: note 92863 added to function.array-unshift
Groups: php.notes 
Request: Send a blank email to php-notes+get-159364@lists.php.net to get a copy of this message
Fixed solution: 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 = array_reverse( $array, true ); $array[$key] = $value; $array = array_reverse( $array, true ); return count( $array ); } ?> ---- Server IP: 82.135.230.5 Probable Submitter: 193.219.74.146 ---- Manual Page -- http://www.php.net/manual/en/function.array-unshift.php Edit -- https://master.php.net/note/edit/92863 Del: integrated -- https://master.php.net/note/delete/92863/integrated Del: useless -- https://master.php.net/note/delete/92863/useless Del: bad code -- https://master.php.net/note/delete/92863/bad+code Del: spam -- https://master.php.net/note/delete/92863/spam Del: non-english -- https://master.php.net/note/delete/92863/non-english Del: in docs -- https://master.php.net/note/delete/92863/in+docs Del: other reasons-- https://master.php.net/note/delete/92863 Reject -- https://master.php.net/note/reject/92863 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159364) next »