1. Go to this page and download the library: Download leaphly/price 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/ */
leaphly / price example snippets
$tShirtPrice = new Price(
[
'EUR' => 300,
'USD' => 400
],
['EUR/GBP 0.7900'] // array of conversions
);
echo $tShirtPrice->inEUR(); // 300 same as ->getAmount('EUR')
echo $tShirtPrice->inUSD(); // 400 same as ->getAmount('USD')
echo $tShirtPrice->inGBP(); // 237 same as ->getAmount('GBP')
$ticketPrice = new Price(
[
'EUR' => 100,
'USD' => 130
],
['EUR/GBP 0.7901'] // this is an array of conversions with the ISO standard format.
);
echo $ticketPrice->inEUR(); // 100
echo $ticketPrice->inGBP(); // 79 is calculated
var_dump($ticketPrice->availableCurrencies()); // array with EUR, USD, GBP
public function inXYZ($currency); // ZYX is a valid currency like EUR or GBP
public function getAmount($currency);
public function hasAmount($currency);
public function availableCurrencies();
public function equals(Price $other);
public function add(Price $addend);
public function subtract(Price $subtrahend);
public function multiply($multiplier);
public function divide($divisor);
public function isZero();
$ticketPrice = new Price(
[
'EUR' => 100,
'USD' => 130
],
['EUR/GBP 0.7901'] // this is an array of conversions
);
$shirtPrice = new Price(
[
'EUR' => 200,
'CHF' => 300,
'GBP' => 400
],
);
// sum
$sumPrice = $ticketPrice->add($shirtPrice);
$sumPrice->inEUR(); // 100+200= 400
$sumPrice->inGBP(); // 79+400= 479
$sumPrice->inUSD(); // 130
$sumPrice->inCHF(); // 300
php
$price = new Price ....
foreach ($price as $money) {
echo $money->getAmount() . ' in '. $money->getCurrencies();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.