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
是的这是!我的问题,我从来不知道或看过整个命令,谢谢。 –