PHP code example of imitronov / cbrf-currency-rate
1. Go to this page and download the library: Download imitronov/cbrf-currency-rate library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
imitronov / cbrf-currency-rate example snippets
// ...
use Imitronov\CbrfCurrencyRate\Client;
$cbrf = new Client();
$currencyRates = $cbrf->getCurrencyRates();
/**
* Перебор всех доступных валют
*/
foreach ($currencyRates as $currencyRate) {
echo sprintf(
'1 %s = %s RUB' . PHP_EOL,
$currencyRate->getCharCode(),
$currencyRate->getRate()
);
}
/**
* Получение курса по нужной валюте
*/
$usdCurrencyRate = $cbrf->getCurrencyRateByCharCode('USD');
echo sprintf(
'1 %s = %s RUB',
$usdCurrencyRate->getCharCode(),
$usdCurrencyRate->getRate(),
);