php array question I like to know a way to pull out a variable then implode it?

  • Thread starter Thread starter White W
  • Start date Start date
W

White W

Guest
i've scoured the php manual for a better way of doing the following:
I want to take out 1 item from an array and put it back together and store it.. example

$widgets = array(1,2,3,4,5,6,7,8,9,0);

lets say during runtime i want to remove the number 4 so the new array looks like
$widgets[0]=1;
$widgets[1]=2;
$widgets[2]=3;
$widgets[3]=5;
...etc
what i've done so far is an old fashion loop keep in mind this is all in mysql for data retrieval :
$widgets = explode(',',$thearray);
$tempstr = '';
$desired_removed_value = 4;
for ($i=0;$i<=count($widgets);$i++){//yes old "basic" habits die hard
if ($widgets[$i] != $disired_removed_value){
$tempstr = $tempstr.$widgets[$i];
}
from here on i can just implode it back into the sql.
this to me seems like a long way to do something simple, is there a faster more "economical" way to do this?
i've been studying the following page:
http://www.php.net/array
for days - i might be getting blurry eyed :P
thanks for any tips

}
 
Back
Top