我有一個代碼,以貨幣輸出轉換爲JSON效應初探我怎麼可以給標識符這個JSON輸出中
<?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));
?>
輸出
{"item":[[55.81,"india.png"],[0.77,"europe.png"],[101.07,"japan.png"]]}
我想提供像55.81 as amount
標識,india.png as image
。
像期望的輸出
{"item":[{"amount":"55.7","image"="india.png"},{"amount"="0.77","image"="europe.png"},{"amount"="101.07","image"="japan.png"}]}
我能得到這個幫助。
感謝
WUT? 「標識符」你是什麼意思?索引? – HamZa
你已經試過了什麼?在這個函數中,你不會用$ amount做任何事情,例如... –