note 40035 deleted from function.array-splice by nlopess

From: Date: Thu, 19 Feb 2004 15:15:41 +0000
Subject: note 40035 deleted from function.array-splice by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65404@lists.php.net to get a copy of this message
Note Submitter: bitmore.co.kr ---- //Original and Source - Modify paule at cs dot tamu dot edu 26-May-2002 08:02 //Compare Source - //richard at richard-sumilang dot com //23-Nov-2002 04:27 //IndexKey Campare Sample Test ///Other Sample /* function key_array_splice(&$input, $key_ofs, $length=NULL, $replacement=NULL) { if($length===NULL || $length<0) $count = $length+count($input); foreach($input as $key=>$value){ if(!$key_found){ if($key === $key_ofs){ $key_found=true; if($length!==NULL && $length>=0) $count=$length; if(is_array($replacement)) { foreach($replacement as $r_key=>$r_value) $new_array[$r_key]=$r_value; }else if( $replacement !== NULL ) $new_array[$key] = $replacement; } } if($key_found){ if($count>0) $ret_array[$key]=$value; else $new_array[$key]=$value; } $count--; } $input=$new_array; return $ret_array; } $test = array(1,2,3,4,5); print_r( key_array_splice( $test,0 ) );echo "<br>";//Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) $test = array(1,2,3,4,5); print_r( key_array_splice( $test,0,1 ) );echo "<br>";//Array ( [0] => 1 ) print_r( $test );echo "<br>";//Array ( [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) $test = array(1,2,3,4,5); print_r( key_array_splice( $test,0,1,"Deck" ) );echo "<br>";//Array ( [0] => 1 ) print_r( $test );echo "<br>";//Array ( [0] => Deck [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) /*

« previous php.notes (#65404) next »