简体   繁体   English

如何更新此数组中的特定值? (php)

[英]How can I update a specific value in this array? (php)

I have the following array, $cart which is structured like so:我有以下数组, $cart ,其结构如下:

Array
(
    [0] => Array
        (
            [sku] => TEST1
            [size] => s
            [qty] => 1
        )

)

how can I update the qty to 2 directly using php and not using a foreach loop (nb. assume I have the index value (0) already).如何使用 php 直接将数量更新为 2,而不使用 foreach 循环(注意,假设我已经有索引值(0))。

Thanks谢谢

Like this:像这样:

$array[0]['qty'] = 2;

Unless I'm missing something here, if you already know you want to update index 0:除非我在这里遗漏了什么,否则如果您已经知道要更新索引 0:

$foo[0]['qty'] = 2;

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

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