繁体   English   中英

如何从 laravel 中的数组中更新和删除值

[英]how to update and delete value from array in laravel

我有一个数组 $cart 像

    array:5 [▼
  188 => array:17 [▼
    "user_id" => "176"
    "product_id" => "188"
    "qty" => "2"
    "date" => "03-05-2020"
    "product_type" => "rear type"
    "custom_color_title" => ""
    "custom_color_price" => ""
    "bolt_title" => ""
    "bolt_price" => ""
    "hub_center_rings_title" => ""
    "hub_center_rings_price" => ""
    "wheel_spacers_title" => ""
    "wheel_spacers_price" => ""
    "tire_pressure_title" => ""
    "tire_pressure_price" => ""
    "product_price" => 1890
    "product_size" => ""
  ]
  176 => array:17 [▼
    "user_id" => ""
    "product_id" => "176"
    "qty" => "2"
    "date" => "03-05-2020"
    "product_type" => "wheel type"
    "custom_color_title" => ""
    "custom_color_price" => ""
    "bolt_title" => ""
    "bolt_price" => ""
    "hub_center_rings_title" => ""
    "hub_center_rings_price" => ""
    "wheel_spacers_title" => ""
    "wheel_spacers_price" => ""
    "tire_pressure_title" => ""
    "tire_pressure_price" => ""
    "product_price" => 1680
    "product_size" => ""
  ]
  224 => array:17 [▶]
] 

如何更新 188 position 的数量值并删除 176 position? $cart 是 session 值存储变量,我有$qty = $_POST['qty']; $cartid = $_POST['cartid']; $qty = $_POST['qty']; $cartid = $_POST['cartid']; $qty 是更新值,$cartid 是位置值。

对于更新,您可以使用它

$array[188] = [
    'item_name' => 'value',
     ...
];

删除你可以使用这个

unset($array[176]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM