aretheythesame.php 353 B

1234567891011121314151617
  1. <?php
  2. function comp($a = [], $b = []): bool {
  3. // Protect against degenerate cases using invalid arguments.
  4. if (gettype($a) !== gettype($b) || count($a) != count($b)) {
  5. return false;
  6. }
  7. sort($a);
  8. sort($b);
  9. for ($i = 0; $i < count($a); $i++) {
  10. $x = $a[$i]*$a[$i];
  11. if ($x != $b[$i]) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. }