Forum Moderators: coopster
<?php
$drop1="Drop";
$item0="Zero";
$item1="One";
$item2="Two";
$dropa = array($drop0,$drop1,$drop2);
$itema = array($item0,$item1,$item2);
print "<br>itema array: ";
print_r(array_values($itema));
print "<br>";
$dr=0;
while($dr < 3){
if($dropa[$dr]=="Drop"){
unset($itema[$dr]);
}
$dr++;
}
print "<br>itema array after unset: ";
print_r(array_values($itema));
print "<br>";
print "itema[0]: ".$itema[0]."<br>";
print "itema[1]: ".$itema[1]."<br>";
?>
The output in my browser is:
itema array: Array ( [0] => Zero [1] => One [2] => Two )
itema array after unset: Array ( [0] => Zero [1] => Two )
itema[0]: Zero
itema[1]:
HAH?
Wha hoppened to $itema[1]?
Arrays [php.net]
To change a certain value, just assign a new value to an element specified with its key. If you want to remove a key/value pair, you need to unset() it.