I have a problem with the following.
I am trying to substitute two elements in an array with an empty string dependant
on a large number of conditional statements. Method "A" works fine but I am trying to be
as efficient with the code as possible. I have tried method "B" which seems to work sometimes
but not others?
Method A
if($d="x") {$new_array = $array("","",$a[2],$a[3],$a[4],$a[5]);}
elseif($d="y"){$new_array = $array($a[0],$a[1],"","",$a[4],$a[5]);}
elseif($d="z"){$new_array = $array($a[0],$a[1],$a[2],$a[3],"","");}
Method B
$old_array = $array($a[0],$a[1],$a[2],$a[3],$a[4],$a[5]);
if($d="x") {$xyx = str_replace($a[0],"",$old_array); $new_array = str_replace($a[1],"",$xyz);} }
elseif($d="y"){$xyx = str_replace($a[2],"",$old_array); $new_array = str_replace($a[3],"",$xyz);}
elseif($d="z"){$xyx = str_replace($a[4],"",$old_array); $new_array = str_replace($a[5],"",$xyz);}
Could anyone suggest what if anything is wrong with "B" and is there a better way of doing this
Thanks
Rob