PHP code example of p4 / excel-goalseek
1. Go to this page and download the library: Download p4/excel-goalseek 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/ */
p4 / excel-goalseek example snippets
php
//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);