简体   繁体   中英

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

I have the following array, $cart which is structured like so:

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).

Thanks

Like this:

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

Unless I'm missing something here, if you already know you want to update index 0:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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