tags:

views:

17

answers:

1

I have an array returning like this from PayPal:

Array
(
    [responseEnvelope.timestamp] => 2010-09-07T23%3A06%3A33.737-07%3A00
    [responseEnvelope.ack] => Success
    [responseEnvelope.correlationId] => b9d9ca4f54f44
    [responseEnvelope.build] => 1437064
    [estimatedAmountTable.currencyConversionList(0).baseAmount.code] => USD
    [estimatedAmountTable.currencyConversionList(0).baseAmount.amount] => 1.00
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(0).code] => EUR
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(0).amount] => 0.71
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(1).code] => USD
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(1).amount] => 1.00
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(2).code] => GBP
    [estimatedAmountTable.currencyConversionList(0).currencyList.currency(2).amount] => 0.48
)

The function that does this is:

function _deformat($nvpstr) {
    foreach (explode('&', $nvpstr) as $nvp) {
        list($key, $value) = explode('=', $nvp);
        $data[$key] = $value;
    }
    return $data;
}

I want the array like this:

..
[EUR]
   [amount] => 0.71
[GBP]
   [amount] => 0.48
...

I can get the key:

$new_key = substr(strrchr($key, "."), 1);

but I'm in a flat spin after that.

A: 

you can run on the array , and change the keys and the values like :

foreach ($myarray as $key=>$val) {

    if(strstr($key,'code')){
      $myarray[$val] = $myarray[str_replace('code','amount',$key)];
      unset($myarray[$key]);
      unset($myarray[str_replace('code','amount',$key)]);
    }
}
Haim Evgi