PHP code example of fabyo0 / weight-conversion

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

    

fabyo0 / weight-conversion example snippets


use Fabyo0\WeightConversion\WeightConversion;

// Static factory methods
$weight = WeightConversion::fromKilograms(100);
$weight = WeightConversion::fromPounds(220);

// Method chaining
$total = WeightConversion::fromKilograms(50)
    ->add(25, 'kg')
    ->subtract(10, 'lb')
    ->toKilograms();

// Comparison methods
$weight1 = WeightConversion::fromKilograms(100);
$weight2 = WeightConversion::fromPounds(220);

$weight1->isGreaterThan($weight2); // true/false

// Formatting output
$weight = new WeightConversion(75.5, 'kg');
echo $weight->format(2); // "75.50 kg"

// Get supported units
WeightConversion::getSupportedUnits(); // ['kg', 'g', 'mg', 'lb', 'oz', 't']