删除数组Session :: forget()Laravel 5.2

时间:2016-05-10 11:39:59

标签: php arrays laravel

我想删除1个数组Session::push('product', $array);例如:当点击按钮删除(x)时,会话将删除数组[0]和Session::push('product', $array);只是仍然数组[1]

"product" => array:1 [▼
    0 => array:5 [▼
      "id" => "9"
      "name" => "Điện thoại Samsung Galaxy A5 2016"
      "price" => "888888990"
      "picture" => "16046_315945335227228_2087086595407127217_n.jpg"
      "qty" => "1"
    ]
    1 => array:5 [▼
      "id" => "10"
      "name" => "Điện thoại Samsung Galaxy A5 2016"
      "price" => "888888990"
      "picture" => "16046_315945335227228_2087086595407127217_n.jpg"
      "qty" => "1"
    ]
  ]

1 个答案:

答案 0 :(得分:0)

<?php

// Get the product array
$product = Session::get('product');

// Unset the first index (or provide an index)
unset($product[0]);

// Overwrite the product session
Session::put('product', $product);