Write a PHP program to check three given integers (small, medium and large) and return true if the difference between small and medium and the difference between medium and large is same.
<?php function test($x, $y, $z) { if ($x > $y && $x > $z && $y > $z) return $x - $y == $y - $z; if ($x > $y && $x > $z && $z > $y) return $x - $z == $z - $y; if ($y > $x && $y > $z && $x > $z) return $y - $x == $x - $z; if ($y > $x && $y > $z && $z > $x) return $y - $z == $z - $x; if ($z > $x && $z > $y && $x > $y) return $z - $x == $x - $y; return $z - $y == $y - $x; } var_dump(test(4, 5, 6)); var_dump(test(7, 12, 13)); var_dump(test(-1, 0, 1));
Sample Output:
bool(true) bool(false) bool(true)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer