簡體   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