Do it like this:
foreach ($_SESSION['item'] as $key => $value) {
if($value['product_id'] == $product_id) {
unset($_SESSION['item'][$key]);
break;
}
}
Вопрос
Temporary registration number of products that I have a session and only post in this sequence to close the session according to the number of items I want to delete, and then only
$product_id = mysql_real_escape_string($_POST['product_id']);
Array (
[0] => Array ( [product_id] => 9 [stock] => 20 )
[1] => Array ( [product_id] => 8 [stock] => 30 )
[2] => Array ( [product_id] => 7 [stock] => 26 )
[3] => Array ( [product_id] => 6 [stock] => 42 )
)
In this way I tried, but did not
foreach ($_SESSION['item'] as $item)
{
if($item['product_id'] == $product_id){
unset($item['item']['product_id']);
}
}
Решение
Do it like this:
foreach ($_SESSION['item'] as $key => $value) {
if($value['product_id'] == $product_id) {
unset($_SESSION['item'][$key]);
break;
}
}