p4/excel-goalseek

Utility to emulate goalseek function in PHP

v2.0.0 2021-09-02 19:30 UTC

This package is auto-updated.

Last update: 2024-04-09 01:07:34 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

Utility to emulate goalseek function in PHP. This fork was made for very specific project, and there is no promise to keep any BC.

This library is a fork of PHP-Excel-GoalSeek

Install

Use package from packagist.

composer require p4/excel-goalseek

Usage

//Define function which for which the value should be found
$callbackTest = function callbackTest($input) {
    $inputForCallbackTest2 = $input * 8;
    return $inputForCallbackTest2 - 12;
};

//Instantiate goal seek class
$goalseek = new ExcelGoalSeek();
//$goalseek->debug = true;

//I want to know which input needs callbackTest to give me 301
$expected_result = 300;

//Calculate the input to get you goal, with accuracy
$input = $goalseek->calculate($callbackTest, $expected_result, 5);

//Voilá!
echo "\$input: " . $input . "<br />";

//Let's test our input it is close
$actual_result = $callbackTest($input);
//Searched result of function
echo "Searched result of $callbackTest(\$input) = " . $expected_result . "<br />";
//Actual result of function with calculated goalseek
echo "Actual result of $callbackTest(" . $input . ") = " . $actual_result . "<br />";
//If difference is too high, you can improve the class and send me it your modifications ;)
echo "Difference = " . ($actual_result - $expected_result);

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.