I have an array with 5 columns and 4 rows. I want to delete one of the rows based on the variable "del" that I pass. If the variable "del" matches the first column of any of the 4 rows, I want to delete that row from the array. I have been trying to use the "unset" function, and can't seem to remove the row. Below is my code:
#delete row from cart array if delete link pressed and variable passed
if ($_GET['del'] <>"")
{
echo "delete value is:".$_GET['del'];
$arr=$_SESSION['cart'];
foreach ($arr as $rownum=>$value)
{
echo "<br>Row values are:".$arr[$rownum][0];
if ($arr[$rownum][0]==$_GET['del'])
{
echo "it's a match";
unset($arr[$rownum]);
}
}
}
The "del" variable is being passed correctly. It matches the specified column in the array, but it seems that
unset($arr[$rownum]);
is not working to delete that row from the array. Can anyone provide me with some guidance?