note 40074 added to function.array-unshift

From: Date: Fri, 20 Feb 2004 21:17:25 +0000
Subject: note 40074 added to function.array-unshift
Groups: php.notes 
Request: Send a blank email to php-notes+get-65459@lists.php.net to get a copy of this message
//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) ); ---- Manual Page -- http://www.php.net/manual/en/function.array-unshift.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40074 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40074&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40074&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65459) next »