PHP code example of ashallendesign / exchange-rates

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

    

ashallendesign / exchange-rates example snippets


$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$exchangeRates->currencies();

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRate('GBP', 'EUR');

// $result: '1.10086'

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);

// $result: [
//     'EUR' => '1.10086',
//     'USD' => '1.25622'
// ];

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    'EUR',
    Carbon::now()->subWeek(),
    Carbon::now()
);

// $result: [
//     '2020-07-07' => [
//         'EUR' => '1.1092623405',
//     ],
//     '2020-07-08' => [
//         'EUR' => '1.1120625424',
//     ],
//     '2020-07-09' => [
//         'EUR' => '1.1153867604',
//     ],
// ];

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    ['EUR', 'USD'],
    Carbon::now()->subDays(3),
    Carbon::now(),
);

// $result: [
//     '2020-07-07' => [
//         'EUR' => '1.1092623405',
//         'USD' => '1.2523571825',
//      ],
//     '2020-07-08' => [
//         'EUR' => '1.1120625424',
//         'USD' => '1.2550737853',
//      ],
//     '2020-07-09' => [
//         'EUR' => '1.1153867604',
//         'USD' => '1.2650716636',
//      ],
// ];

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->convert(100, 'GBP', 'EUR');

// $result: '110.15884906'

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->convert(
    100,
    'GBP',
    ['EUR', 'USD'],
    Carbon::now(),
);

// $result: [
//     'EUR' => '110.15884906',
//     'USD' => '125.30569081'
// ];

$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$exchangeRates->convertBetweenDateRange(
    100,
    'GBP',
    'EUR',
    Carbon::now()->subDays(3),
    Carbon::now()
);

// $result: [
//     '2020-07-07' => [
//         'EUR' => '110.92623405',
//      ],
//     '2020-07-08' => [
//         'EUR' => '111.20625424',
//      ],
//     '2020-07-09' => [
//         'EUR' => '111.53867604',
//      ],
// ];

$exchangeRates = new ExchangeRate();
$result = $exchangeRates->exchangeRateBetweenDateRange('GBP', ['EUR', 'USD'], Carbon::now()->subDays(3), Carbon::now());

// $result: [
//     '2020-07-07' => [
//         'EUR' => '110.92623405',
//         'USD' => '125.23571825',
//      ],
//     '2020-07-08' => [
//         'EUR' => '111.20625424',
//         'USD' => '125.50737853',
//      ],
//     '2020-07-09' => [
//         'EUR' => '111.53867604',
//         'USD' => '126.50716636',
//      ],
// ];