PHP code example of masum-packagist / php-math-operations

1. Go to this page and download the library: Download masum-packagist/php-math-operations 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/ */

    

masum-packagist / php-math-operations example snippets




asumPackagist\PhpMathOperations\MathOperations;


$math = new MathOperations();

echo $math->add(5, 10);      // Output: 15
echo $math->subtract(10, 5); // Output: 5
echo $math->multiply(4, 5);  // Output: 20
echo $math->divide(10, 2);   // Output: 5

echo $math->exp(1);          // Output: 2.718281828459
echo $math->log(10);         // Output: 2.302585092994 (natural log)
echo $math->log10(100);      // Output: 2

echo $math->sin(pi() / 2);   // Output: 1
echo $math->cos(0);          // Output: 1
echo $math->tan(pi() / 4);   // Output: 1

echo $math->degToRad(180);   // Output: 3.14159265359
echo $math->radToDeg(pi());  // Output: 180

echo $math->ceil(4.3);       // Output: 5
echo $math->floor(4.7);      // Output: 4
echo $math->round(4.5678, 2);// Output: 4.57
echo $math->abs(-10);        // Output: 10

echo $math->factorial(5);    // Output: 120
echo $math->gcd(48, 18);     // Output: 6
echo $math->lcm(12, 15);     // Output: 60

echo $math->permutation(5, 2); // Output: 20
echo $math->combination(5, 2); // Output: 10

echo $math->random(1, 100);   // Output: a random number between 1 and 100

$values = [1, 2, 3, 4];
echo $math->sum($values);     // Output: 10
echo $math->product($values); // Output: 24

echo $math->pythagoras(3, 4); // Output: 5