PHP code example of zlikavac32 / php-measure-units
1. Go to this page and download the library: Download zlikavac32/php-measure-units 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/ */
zlikavac32 / php-measure-units example snippets
$angle = 90;
echo sin($angle);
$angle = new Quantity(90, 'degc');
echo sin($angle->in('rad')->value());
use Zlikavac32\UnitsOfMeasure\Defaults;
use Zlikavac32\UnitsOfMeasure\MapUnitNormalizer;
use Zlikavac32\UnitsOfMeasure\NativeRuntime;
use Zlikavac32\UnitsOfMeasure\SiFormParser;
$baseUnits = Defaults::siBaseUnits();
$transitionMap = Defaults::siDerivedUnits()
->merge(Defaults::otherMetricUnits());
$imperialUnits = Defaults::imperialUnits();
$parser = new SiFormParser($baseUnits->merge($transitionMap->keys())->toArray(), $imperialUnits->keys()->toArray());
$normalizer = new MapUnitNormalizer(
$transitionMap->merge($imperialUnits),
$baseUnits
);
$unitsOfMeasure = new NativeRuntime(
$parser,
$normalizer
);
$gasolineConsumptionPer100Km = $unitsOfMeasure['l.100 km-1'];
// How many kilometers can we make with one liter if we had consumption of 4 liters per 100 kilometers
echo $gasolineConsumptionPer100Km->in('km.l-1')->applyTo(4);