PHP code example of nehalpatel / unit-conversion

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

    

nehalpatel / unit-conversion example snippets


return [
];

use NehalPatel\UnitConversion\Temperature\Celsius;
use NehalPatel\UnitConversion\Temperature\Fahrenheit;
use NehalPatel\UnitConversion\Weight\Kilogram;

//convert from Celsius to Fahrenheit
UnitConversion::from(new Celsius(30))->toFahrenheit()->convert();
Celsius::from(20)->toFahrenheit()->convert();

//convert from Fahrenheit to Celsius
UnitConversion::from(new Fahrenheit(68))->toCelsius()->convert();
Fahrenheit::from(68)->toCelsius()->convert();

//Weight Conversion
UnitConversion::from(new Kilogram(10))->toGram()->convert();
Kilogram::from(10)->toGram()->convert();
bash
php artisan vendor:publish --tag="unit-conversion-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="unit-conversion-config"
bash
php artisan vendor:publish --tag="unit-conversion-views"