0

I have a code to convert the currency output as a JSON reponse

<?php
$response = array();
function currency($from_Currency, $to_Currency, $amount)
{
    $amount        = urlencode($amount);
    $from_Currency = urlencode($from_Currency);
    $to_Currency   = urlencode($to_Currency);
    $url           = "Myurl";
    $ch            = curl_init();
    $timeout       = 0;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $rawdata = curl_exec($ch);
    curl_close($ch);
    $data = explode('"', $rawdata);
    $data = explode(' ', $data['3']);
    $var  = $data['0'];
    return round($var, 2);
}

$result = array(
    array(
        currency("USD", "INR", 1.00),
        "india.png"
    ),
    array(
        currency("USD", "EUR", 1.00),
        "europe.png"
    ),
    array(
        currency("USD", "JPY", 1.00),
        "japan.png"
    )
);
echo json_encode(array('item' => $result));
?>

Output

{"item":[[55.81,"india.png"],[0.77,"europe.png"],[101.07,"japan.png"]]}

I want to provide the identifier like 55.81 as amount, india.png as image.

Like desired output

{"item":[{"amount":"55.7","image"="india.png"},{"amount"="0.77","image"="europe.png"},{"amount"="101.07","image"="japan.png"}]}

Can I get the help in this.

Thanks

4

2 回答 2

3

代替

array(
    currency("USD", "INR", 1.00),
    "india.png"
)

array(
    "amount" => currency("USD", "INR", 1.00),
    "image" => "india.png"
)
于 2013-05-27T08:19:58.480 回答
1

你可以尝试改变:

$result = array(
        array(
            'amount' => currency("USD", "INR", 1.00),
            'image' => "india.png"
        ),
        array(
            'amount' => currency("USD", "EUR", 1.00),
            'image' => "europe.png"
        ),
        array(
            'amount' => currency("USD", "JPY", 1.00),
            'image' => "japan.png"
        )
    );
于 2013-05-27T08:25:51.813 回答