1
我做了基於一對夫婦的PHP腳本‘如果’的語句。$ depOption只能是bitcoin
,ethereum
,lisk
,EUR
或USD
。「ELSEIF」不工作
在if
聲明內容作品,然而在ELSEIF語句的內容返回$VAR
爲0
我自己測試了這些語句的代碼,並且他們的工作。只有當我把它們放在我ELSEIF聲明,他們不工作。
if ($depOption == "bitcoin" or "ethereum" or "lisk")
{
// Get information on altcoin values
$request = 'https://api.coinmarketcap.com/v1/ticker/';
$response = file_get_contents($request);
$data = json_decode($response, true);
$price = null;
foreach ($data as $item) {
if ($item["id"] == "$depOption") {
$VAL = $item["price_usd"];
break;
}
}
}
elseif ($depOption == "EUR")
{
// Get EUR exchange rate
$eurrequest = 'http://api.fixer.io/latest';
$eurresponse = file_get_contents($eurrequest);
$eurdata = json_decode($eurresponse, true);
$VAL = $eurdata['rates']['USD'];
}
elseif ($depOption == "USD")
{
$VAL = 1;
}
else
{
die("Something went wrong.");
}
常見的選擇是'如果(in_array($ depOption,陣列( 「比特幣」, 「復仇」, 「lisk」))'... – nogad
是的這是!我的問題,我從來不知道或看過整個命令,謝謝。 –