note 40074 deleted from function.array-unshift by cece

From: Date: Mon, 29 Nov 2004 13:26:12 +0000
Subject: note 40074 deleted from function.array-unshift by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-81150@lists.php.net to get a copy of this message
Note Submitter: bitmore.co.kr ---- //Original //chris dot NoThxSpam dot given at hp dot com //24-Jul-2003 01:17 //Note Infinite Loop Function function array_key_change($Old, $New, $In, $NewVal=NULL) { //if( !is_array($In) || !array_key_exists($Old,$In) ) return false; //necessary Code $Temp = array(); while(isset($Temp[$Old]) == false) { list($k, $v) = each($In); $Temp[$k] = $v; unset($In[$k]); } if($NewVal == NULL) $NewVal = $Temp[$Old]; unset($Temp[$Old]); $Temp = array_reverse($Temp); $In = array_merge(array($New=>$NewVal), $In); while(list($k,$v) = each($Temp)) $In = array_merge(array($k=>$v), $In); return($In); } $In = array ("apple"=>1, "raspberry"=>2, "orange"=>3, "banana"=>4); //¹«ÇÑÈ÷ ÁøÇàµÈ´Ù.OldŰ¿¡ ´ëÇÑ °ËÁõÇÊ¿ä //infinite Funtion Process //$Old = "test"; //$New = "bull"; //$Old = ""; //$New = "bull"; $Old = "apple"; $New = "bull"; //Array ( [bull] => 1 [raspberry] => 2 [orange] => 3 [banana] => 4 ) //$Old = "apple"; //$New = ""; //Array ( [] => 1 [raspberry] => 2 [orange] => 3 [banana] => 4 ) print_r( array_key_change($Old, $New, $In, $NewVal=NULL) );

« previous php.notes (#81150) next »