php add array,如何在php中的單個數組中添加值

please someone will guide me to how to add the values of below conditions and then update the added value in code .

請有人指導我如何添加以下條件的值,然后更新代碼中的添加值。

how to sum value of where code =low_order_fee and where code= goods_total then update the sum value in where code=goods_total.

如何將code = low_order_fee的where值和code = goods_total的值相加,然后更新code = goods_total的sum值。

Array

(

[0] => Array

(

[order_total_id] => 999

[order_id] => 194

[code] => goods_total

[title] => Goods-Total

[text] => £130.00

[value] => 130.0000

[sort_order] => 1

)

[1] => Array

(

[order_total_id] => 1000

[order_id] => 194

[code] => low_order_fee

[title] => * Carriage

[text] => £10.00

[value] => 10.0000

[sort_order] => 3

)

[2] => Array

(

[order_total_id] => 1001

[order_id] => 194

[code] => sub_total

[title] => Sub-Total

[text] => £130.00

[value] => 130

[sort_order] => 4

)

[3] => Array

(

[order_total_id] => 1002

[order_id] => 194

[code] => tax

[title] => VAT (20%)

[text] => £26.00

[value] => 26.0000

[sort_order] => 5

)

[4] => Array

(

[order_total_id] => 1003

[order_id] => 194

[code] => total

[title] => Invoice Total

[text] => £166.00

[value] => 166.0000

[sort_order] => 9

)

)

1 个解决方案

#1

A rudimentary solution:

一個基本的解決方案:

foreach ($array_var as $key => $item) {

if ($item['code'] == 'low_order_fee') {

$first_val = $item['value'];

}

if ($item['goods_total'] == 'low_order_fee') {

$sec_val = $item['value'];

$position = $key;

}

}

$array_var[$position]['goods_total'] = $first_val + $sec_val;

But maybe you should think about store the values in another way to make easier access to them.

但也許您應該考慮以另一種方式存儲值,以便更容易地訪問它們。

I hope it helps.

我希望它有所幫助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值