Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Last active May 20, 2018 12:33
Show Gist options
  • Save BenMorel/3798ff53a54daaa267969526d3a28b93 to your computer and use it in GitHub Desktop.
Save BenMorel/3798ff53a54daaa267969526d3a28b93 to your computer and use it in GitHub Desktop.
Solve 2 equations with 2 unknowns in PHP
<?php
/**
* Solves the following equations:
*
* a·x + b·y = c
* d·x + e·y = f
*
* Returns an array with [x, y]
*/
function solve($a, $b, $c, $d, $e, $f)
{
$x = $c * $e - $b * $f;
$y = $a * $f - $c * $d;
$z = $a * $e - $b * $d;
return [$x / $z, $y / $z];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment