fork(2) download
  1. <?php
  2.  
  3. // https://stackoverflow.com/a/1343685/5305370
  4.  
  5. function isqrt($n)
  6. {
  7. $b = 0;
  8.  
  9. while($n >= 0)
  10. {
  11. $n = $n - $b;
  12. $b = $b + 1;
  13. $n = $n - $b;
  14. }
  15.  
  16. return $b - 1;
  17. }
  18.  
  19. $a = 9;
  20. $b = isqrt($a);
  21.  
  22. echo "a = ".$a.", sqrt(a) = b = ".$b."\n";
  23. echo "typeof = ".gettype($b)."\n";
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
a = 9, sqrt(a) = b = 3
typeof = integer