-1

My function

function array_push_assoc(&$array, $key, $value){
    echo $key.".".$value."<p>";
    $array[$key] = $value;
    return $array;
}

OUTPUT

USD.736.00

USD.100.00

Array
(
    [USD] => 100.00
)

EUR.736.00

USD.100.00

Array
(
    [EUR] => 736.00
    [USD] => 100.00
)

I WANT OUTPUT

USD.736.00

USD.100.00

Array
(
    [USD] => 836.00 // sum all the same currency
)

EUR.736.00

USD.100.00

Array
(
    [EUR] => 736.00
    [USD] => 100.00
)

Anybody Know how to do this?Please help .Thanks

1
  • 2
    I don't understand how your function is supposed to work. What should it look like when you call it? Commented Jan 28, 2011 at 12:54

1 Answer 1

4

I'm not sure, but i believe that is what you want:

function array_push_assoc(&$array, $key, $value){
    echo $key.".".$value."<p>";
    if (isset($array[$key]))
      $array[$key] += $value;
    else
      $array[$key] = $value;
    return $array;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.