PHP code example of cowshedworks / calculators

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

    

cowshedworks / calculators example snippets


use CowshedWorks\Calculators\CalculationFactory;

$calculator = (new CalculationFactory())
    ->using('p1')
    ->multiplyBy(10)
    ->multiplyBy('p2')
    ->build();

$calculator(10, 30);
// prints 3000

$circumferenceFromDiameter = (new CalculationFactory())
    ->using('p1')
    ->multiplyBy(pi())
    ->build();

$circumferenceFromDiameter(10)
// prints 31.41592653589793

$radiusFromCircumference = (new CalculationFactory())
    ->using('p1')
    ->divideBy(
        (new CalculationFactory())
            ->using(pi())
            ->multiplyBy(2)
    )
    ->build();

$radiusFromCircumference(10)
1.5915494309189497