doutuo1939 2016-07-08 12:06
浏览 130

从Laravel会话中的数组中删除项目

How can I delete only a single item from an array in Laravel with Sessions. When I try to do it now with Session:pull, it just deletes the whole session object with key estate.id and with all the items in the array. I want to match only the object that has the same id as the id received from the input.

Simplified code

$estateId = Input::get('id', null);

if ($processType == "add") {
    Session::push('estate.id', $estateId);
   }
else {
  if (in_array($estateId, $data)) {
     $value = Session::pull('estate.id', $estateId);
  }
}
  • 写回答

1条回答 默认 最新

  • dsorecdf78171 2016-07-08 12:33
    关注

    The Laravel Session service doesn't offer a built in method to remove a value from an array, but there is a workaround you can do with:

    Session::put('key', array_diff(Session::get('key'), ['value']));
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源