sumEven - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of sumEven.php

  1. <?php
  2.  
  3. // напиши функцию которая просуммирует все четные числа от $a до $b
  4. // numbers from 11 to 111 
  5.  
  6. function sumEven(int $min, int $max): int {
  7.     $sum = 0;
  8.     for ($i = $min; $i <= $max; $i++) {
  9.         if ($i % 2 === 0) {
  10.             $sum += $i;
  11.         }
  12.     }
  13.  
  14.     return $sum;
  15. }
  16.  
  17. echo(sumEven(11, 111));
File Description
  • sumEven
  • PHP Code
  • 28 Sep-2023
  • 363 Bytes
You can Share it: