fork download
  1. <?php
  2.  
  3. function f($n) {
  4. return (preg_match('/^\d+$/D', $n) && $n > 0) ? array_sum(range(1, $n)) : false;
  5. }
  6.  
  7. if (!f(2.1)) {
  8. echo 'this is not an integer';
  9. }
  10.  
  11. print_r(f(2.1));
Success #stdin #stdout 0.03s 23804KB
stdin
Standard input is empty
stdout
this is not an integer