PHP code example of amberovsky / currency

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

    

amberovsky / currency example snippets


use Amberovsky\Money\Currency\CurrencyFactory;
use Amberovsky\Money\Currency\ISO4217;

$factory = new CurrencyFactory(new ISO4217(), new PSR16Cache());

$usd = $factory->fromNumericCode(ISO4217::NUMERIC_USD);

// or

$usd = $factory->fromAlphaCode(ISO4217::ALPHA_USD);

// then

$usd->getNumericCode(); // 809
$usd->getDescription(); // US Dollar
$usd->getMinorUnits(); // 2
$usd->getAlphaCode(); // USD
$usd->getSymbol(); // $

// also, these methods could be useful
ISO4217::toNumericCode(string $alphaCode): int
ISO4217::toAlphaCode(int $numericCode): string