Last active
September 17, 2017 14:38
-
-
Save xmoonlight/cabd04bff6506724ff946fef7e868624 to your computer and use it in GitHub Desktop.
Small currency exchange function (PHP, stand-alone)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exchange($amount,$give,$get) { | |
$exchanges=[ | |
'USD:RUB'=>60, | |
'RUB:USD'=>1/60, | |
]; | |
$in=[$give.':'.$get=>$amount]; | |
$key=key($in); | |
if ($amount>0 && $exchanges[$key]) { | |
$out=$exchanges[$key]*$in[$key]; | |
return $out.' '.explode(':',$key,2)[1]; | |
} else return false; | |
} | |
///MAIN//// | |
if ($out=exchange(2,'USD','RUB')) echo $out; | |
else echo 'Exchange is not possible!'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment