0

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.

  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
    )

)

2
  • 1
    Can't even able to understand your question what you want Commented May 7, 2015 at 10:34
  • Please elaborate your question. Where did you get stuck . Here only I understand is where Commented May 7, 2015 at 10:54

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.