PDA

View Full Version : why isn't this unsetting?


sabret00the
07-24-2006, 12:00 PM
echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";

foreach ($formdetails['taglist'] AS $k)
{
if ($k == $tagtodelete)
{
echo $k . $tagtodelete;
unset($formdetails['taglist'][$k]);
}
}
echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";
die;


Array
(
[0] => admining
[1] => amazon
[2] => another tag
[3] => ebs
[4] => ex-girlfriend
[5] => life
[6] => meme
[7] => music
[8] => retest
[9] => singledom
[10] => test
[11] => test again
[12] => wishlist
[13] => work
)

retestretest

Array
(
[0] => admining
[1] => amazon
[2] => another tag
[3] => ebs
[4] => ex-girlfriend
[5] => life
[6] => meme
[7] => music
[8] => retest
[9] => singledom
[10] => test
[11] => test again
[12] => wishlist
[13] => work
)


i even tried
echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";

foreach ($formdetails['taglist'] AS $k => $v)
{
if ($v == $tagtodelete)
{
echo $v . $tagtodelete;
unset($formdetails['taglist'][$tagtodelete]);
}
}
echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";
die;

amykhar
07-24-2006, 02:16 PM
I THINK it should be :


echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";

foreach ($formdetails['taglist'] AS $k => $v)
{
if ($v == $tagtodelete)
{
echo $v . $tagtodelete;
unset($formdetails['taglist'][$k]);
}
}
echo "<pre>";
print_r($formdetails['taglist']);
echo "</pre>";
die;

sabret00the
07-24-2006, 02:23 PM
thanks amy, i'll give it a whirl :)

AN-net
07-24-2006, 04:28 PM
or an array flip will work if you just process the element value.

sabret00the
07-24-2006, 05:31 PM
alternatively for anyone else baffled by this in the future (probably me).

$tagtodelete = urldecode($_POST['tagdelete']);

$formdetails['taglist'] = explode(',', $formdetails['taglist']);

unset($formdetails['taglist'][array_search($tagtodelete, $formdetails['taglist'])]);
$formdetails['taglist'] = implode(',', array_values($formdetails['taglist']));