PHP code example of orkhanahmadov / currencylayer

1. Go to this page and download the library: Download orkhanahmadov/currencylayer 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/ */

    

orkhanahmadov / currencylayer example snippets


use Orkhanahmadov\Currencylayer\CurrencylayerClient;

$client = new CurrencylayerClient('your-access-key-here');

$client = new CurrencylayerClient('your-access-key-here', true);

$client->source('USD')->currency('EUR')->quotes();

$client->source('USD')->currency('EUR', 'AUD')->quotes();
// you can also pass currencies as an array
$client->source('USD')->currency(['EUR', 'AUD'])->quotes();

$client->source('USD')->currency('EUR')->date('2019-05-20')->quotes();

$quotes = $client->source('USD')->currency(['EUR', 'AUD'])->date('2019-05-20')->quotes();

$qoutes->EUR; // returns USD to EUR rate for 2019-05-20
$qoutes->AUD; // returns USD to AUD rate for 2019-05-20

$client->source('USD')->currency('GBP')->convert(10);

$client->source('USD')->currency('GBP')->date('2019-05-20')->convert(10);

$client->source('USD')->currency('GBP', 'EUR')->timeframe('2010-03-01', '2010-04-01');

$timeframe = $client->source('USD')->currency('GBP', 'EUR')->timeframe('2010-03-01', '2010-04-01');

$timeframe->GBP('2010-03-15'); // returns USD to GBP rate for 2010-03-15
$timeframe->EUR('2010-03-20'); // returns USD to EUR rate for 2010-03-20

$client->source('USD')->currency('GBP', 'EUR')->change('2010-03-01', '2010-04-01');

$client->list();