dimanche 18 septembre 2016

"Elseif' not working

I've made a php script based on a couple of "If" statements. $depOption can only be bitcoin, ethereum, lisk, EUR or USD.

Currently I am having some problems. The content in the if statement works, however the content in the elseif statements return $VAR as 0. What's wrong? I've tested the code in these statements by themselves, and they work. Only when I put them in my elseif statements, they don't work.

Thanks in advance for the help.

if ($depOption == "bitcoin" or "ethereum" or "lisk")
{

// Get information on altcoin values
$request = 'http://ift.tt/2ciQcAo';
$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://ift.tt/1UmIXTI';
$eurresponse  = file_get_contents($eurrequest);
$eurdata = json_decode($eurresponse, true);
$VAL = $eurdata['rates']['USD'];
}

elseif ($depOption == "USD")
{
    $VAL = 1;
}

else
{
    die("Something went wrong.");
}

Aucun commentaire:

Enregistrer un commentaire