Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Last active May 8, 2023 19:02
Show Gist options
  • Save stevebauman/5882c13a83bce154d4abb2717b67822b to your computer and use it in GitHub Desktop.
Save stevebauman/5882c13a83bce154d4abb2717b67822b to your computer and use it in GitHub Desktop.
Find Quadratic Roots Challenge
<?php
/**
* @return array An array of two elements containing roots in any order
* @link https://www.testdome.com/questions/php/quadratic-equation/38497
*/
function findRoots($a, $b, $c)
{
return [
(-$b + sqrt(pow($b, 2) - ((4 * $a) * $c))) / (2 * $a),
(-$b - sqrt(pow($b, 2) - ((4 * $a) * $c))) / (2 * $a),
];
}
// Array
// (
// [0] => -1
// [1] => -4
// )
print_r(findRoots(2, 10, 8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment