문제

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;
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top