我的代碼是:$xml = simplexml_load_file('http://www.floatrates.com/daily/gel.xml'); $cur = array($xml);$array = json_decode(json_encode($cur), true);$newArr = [];foreach ($array as $value) { foreach($value['item'] as $key){ array_push($newArr, [ $key['targetCurrency'] => $key ]); print '<pre>'; print_r($newArr); print '</pre>'; }}輸出為https://prnt.sc/terpnc我需要像這個(gè)例子一樣:[USD] => Array( [title] => 1 GEL = 0.32613048 USD [link] => http://www.floatrates.com/gel/usd/ [description] => 1 Georgian lari = 0.32613048 U.S. Dollar [pubDate] => Thu, 9 Jul 2020 12:00:01 GMT [baseCurrency] => GEL [baseName] => Georgian lari [targetCurrency] => USD [targetName] => U.S. Dollar [exchangeRate] => 0.32613048 [inverseRate] => 3.06625741 [inverseDescription] => 1 U.S. Dollar = 3.06625741 Georgian lari)[EUR] => Array( [title] => 1 GEL = 0.28808543 EUR [link] => http://www.floatrates.com/gel/eur/ [description] => 1 Georgian lari = 0.28808543 Euro [pubDate] => Thu, 9 Jul 2020 12:00:01 GMT [baseCurrency] => GEL [baseName] => Georgian lari [targetCurrency] => EUR [targetName] => Euro [exchangeRate] => 0.28808543 [inverseRate] => 3.47119257 [inverseDescription] => 1 Euro = 3.47119257 Georgian lari)我怎樣才能像示例中那樣做到這一點(diǎn)?順便說(shuō)一句,使用我的代碼,我多次獲得相同的值,例如您可以看到 [USD] => 數(shù)組 149 次。
數(shù)組按鍵值更改結(jié)構(gòu)
千萬(wàn)里不及你
2023-07-21 16:08:48