note 40024 added to function.array-splice
| From: | bitmor dot co dot kr at rn2 dot php dot net | Date: | Thu, 19 Feb 2004 09:30:25 +0000 |
| Subject: | note 40024 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65373@lists.php.net to get a copy of this message | ||
//orginal
IndexKey Bad Police
richard at richard-sumilang dot com
23-Nov-2002 04:27
function array_slice2($array, $val, $slice="name"){
switch($slice){
case "name":
while(list($i,$k)=each($array)){
if( $i != $val) { $return[$i]=$array[$i]; print "i = $i,val = $val<br>";}
else print " exit BugShow i = $i,val = $val <br>";
}
break;
case "variable":
while(list($i)=each($array)){
if($array[$i]!=$val) $return[$i]=$array[$i];
}
break;
}
return $return;
}
$list = array( "0" => "zero", "1" => "one",
"2" => "two", "3" => "three", "4" =>
"four", "5" => "five", "6" => "six");
print_r( array_slice2 ( $list,'tne') );echo "<br>";
//YouWantShow ? Array ( [0] => zero [1] => one [2] => two [3] => three [4] =>
four [5] => five [6] => six )
//But BugShow ? Array ( [1] => one [2] => two [3] => three [4] => four [5] =>
five [6] => six )
//PrintShow
//exit BugShow i = 0,val = tne
//i = 1,val = tne
//i = 2,val = tne
//i = 3,val = tne
//i = 4,val = tne
//i = 5,val = tne
//i = 6,val = tne
print_r( array_slice2 ( $list,"one","variable") );echo "<br>";
//Array ( [0] => zero [2] => two [3] => three [4] => four [5] => five [6] => six
)
//
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40024
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40024&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40024&report=yes
Search -- http://master.php.net/manage/user-notes.php