123 - 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 123.php

  1. <?php
  2. $a = [4, 2, 4, 6, 1, 7];
  3. $b = [2, 1, 8, 5];
  4. $fot = 11;
  5. $currentFot = 0;
  6. $i = 0;
  7.  
  8.  
  9. if (count($a) > count($b)) {
  10.     $arrLen = count($a);
  11. } else {
  12.     $arrLen = count($b);
  13. }
  14.  
  15. for ($i = 0; $i < $arrLen; $i++ ) {
  16.     if (isset($a[$i]) and isset($b[$i])) {
  17.         if ($a[$i] > $b[$i]) {
  18.             $currentFot += $b[$i];
  19.         }
  20.     } elseif (isset($a[$i])) {
  21.         $currentFot += $a[$i];
  22.     } else {
  23.         $currentFot += $b[$i];
  24.     }
  25.     
  26.     if ($currentFot >= $fot) {
  27.         break;
  28.     }
  29. }
  30.  
  31. echo $i-1;
File Description
  • 123
  • PHP Code
  • 27 Sep-2022
  • 516 Bytes
You can Share it: