Re: Weird $_POST behavior when trying to unset elements



"comp.lang.php" <phillip.s.powell@xxxxxxxxx> wrote in message
news:1164699920.068844.217930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[PHP]
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF
FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA
$_POST
if ($_POST['hasUpdatedLease'] && (!is_array($leaseObj->errorArray) ||
@sizeof($leaseObj->errorArray) == 0)) {
print_r(array_keys($_POST));
@reset($_POST);
$tempPost = $_POST;
foreach ($_POST as $key => $val) if (strpos($key, 'new_') === 0)
array_remove($tempPost, $tempPost[$key]);
@reset($_POST);
$_POST =& $tempPost;
print_r(array_keys($_POST));
}
[/PHP]

For some reason, even though the condition is always met when I click
any of the form submit images, the following "weird behavior patterns"
occur:

1) If I click the "Add" submit image, all $_POST values whose keys
start with "new_" should be removed from $_POST. However,
$_POST['new_audited'] and $_POST['new_reoccuring'] remain

2) If I click the "Delete" submit image, all $_POST values whose keys
start with "new_" should be removed from $_POST. However, *ALL* of
them remain in $_POST untouched!

I can verify that I enter the conditional block by my arrays appearing
on screen every time.

Any reason why this is happening that I missed?



Never heard of array_remove, I wonder what it does. Could it be it's not
actually removing anything? Why not just:
unset($tempPost[$key]);

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@xxxxxxxxxxxxx | rot13(xvzzb@xxxxxxxxxxxxx)


.


Quantcast