PHP code example of jstewmc / fx

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

    

jstewmc / fx example snippets


use Jstewmc\Fx;

(new Constant(1))(3);         // returns 1
(new Equality())(3);          // returns 3
(new Linear(1, 2))(3);        // returns 5 (1 * 3 + 2)
(new Quadratic(1, 2, 3))(4);  // returns 27 (1 * 4 ^ 2 + 2 * 4 + 3)
(new Power(1, 2))(3);         // returns 9 (1 * 3 ^ 2)
(new Exponential(1))(2);      // returns 1 (1 ^ 2)

use Jstewmc\Fx

$fx = new Constant(1);

$fx(1);  // returns 1
$fx(2);  // returns 1
$fx(3);  // returns 1

use Jstewmc\Fx;

$fx = new Equality();

$fx(1);  // returns 1
$fx(2);  // returns 2
$fx(3);  // returns 3

use Jstewmc\Fx;

$fx = new Linear(1, 2);

$fx(1);  // returns 3 (1 * 1 + 2)
$fx(2);  // returns 4 (1 * 2 + 2)
$fx(3);  // returns 5 (1 * 3 + 2)

use Jstewmc\Fx;

$fx = new Quadratic(1, 2, 3);

$fx(1);  // returns 5 (1 * 1 ^ 2 + 2 * 1 + 3)
$fx(2);  // returns 11 (1 * 2 ^ 2 + 2 * 2 + 3)
$fx(3);  // returns 18 (1 * 3 ^ 2 + 2 * 3 + 3)

use Jstewmc\Fx;

$fx = new Power(1, 2);

$fx(1);  // returns 1 (1 * 1 ^ 2)
$fx(2);  // returns 4 (1 * 2 ^ 2)
$fx(3);  // returns 9 (1 * 3 ^ 2)

use Jstewmc\Fx;

$fx = new Exponential(2);

$fx(1);  // returns 2 (2 ^ 1)
$fx(2);  // returns 4 (2 ^ 2)
$fx(3);  // returns 8 (2 ^ 3)