PHP code example of philipbrown / money

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

    

philipbrown / money example snippets


// Create a new Money object representing $5 USD
$m = Money::init(500, 'USD');
$m = new Money(500, 'USD');

$m->cents; // 500
$m->currency; // United States Dollar

$m = Money::init(500, 'USD');

$m->isSameCurrency(Money::init(500, 'GBP')); // false

$one = Money::init(500, 'USD');
$two = Money::init(500, 'USD');
$three = Money::init(501, 'USD');

$one->equals($two); // true
$one->equals($three); // false

$one = Money::init(500, 'USD');
$two = Money::init(500, 'USD');
$three = $one->add($two);
$three->cents // 1000

$one = Money::init(500, 'USD');
$two = Money::init(500, 'GBP');

$three = $one->add($two); // Money\Exception\InvalidCurrencyException