I have the following code, but it does not work, I don't know what mistake I am committing due to which this code does not work:
Here is the code:
<?php session_start();
if (isset($_GET['indexNo']) && is_numeric($_GET['indexNo']) && !empty($_GET['indexNo']))
{
$indx = $_GET['indexNo'];
foreach($_SESSION['itemsOrder'] as $key => $val)
{
echo "$key => $val <br> " ;
if($indx == $val)
{
unset($_SESSION['itemsOrder'][$val]);
}
else
{
echo "indexNo was not unset <br>";
}
}
}
else
{
echo "indexNo not received!";
}
?>
Should be $key not the $val . Try with -
if($indx == $key)
{
unset($_SESSION['itemsOrder'][$key]);
}
No need to use isset & empty together.
if (isset($_GET['indexNo']) && is_numeric($_GET['indexNo']))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With