我有一个看起来像这样的数组:
Array (
[0] => Array (
[id] => 18
[name] => book
[description] =>
[quantity] => 0
[price] => 50
[status] => Brand New
)
[1] => Array (
[id] => 19
[name] => testing
[description] => for testing
[quantity] => 2
[price] => 182
[status] => Brand New
)
[2] => Array (
[id] => 1
[name] => Fruity Loops
[description] => dj mixer
[quantity] => 1
[price] => 200
[status] => Brand New
)
)
我希望能够删除数组中的一整行(当用户单击删除链接时)说array[1]
:
[1] => Array (
[id] => 19
[name] => testing
[description] => for testing
[quantity] => 2
[price] => 182
[status] => Brand New
)
我有这段代码,我试图根据产品的 id 删除,但它不起作用
//$_SESSION['items'] is the array and $delid is the "product id" gotten when a user clicks delete on a particular row.
foreach ($_SESSION['Items'] as $key => $products) {
if ($products['id'] == $delid) {
unset($_SESSION['Items'][$key]);
}
}
我该如何实施?谢谢