aa-test - 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 aa-test.php

  1. <?php
  2.  
  3. function testTask($word1, $word2){
  4.     $cnt = 0;
  5.     foreach($word2 as $key=>$char){
  6.         if(!isset($word1[$cnt])) return false;
  7.         //echo $char.' == '.$word1[$cnt].'('.$cnt.')'.PHP_EOL;
  8.         
  9.         if($char !== $word1[$cnt]){
  10.             if(is_numeric($char)){
  11.                 $cnt += $char;
  12.             } else {
  13.                 return false;
  14.             }
  15.         } else {
  16.             $cnt++;
  17.         }
  18.     }
  19.     return true;
  20. }
  21.  
  22. $testWords = [['anton', 'an3n'],['anton', 'an2n']];
  23. foreach($testWords as $case){
  24.     $word1 = str_split($case[0]);
  25.     $word2 = str_split($case[1]);
  26.     var_dump(testTask($word1,$word2));
  27. }
File Description
  • aa-test
  • PHP Code
  • 27 Sep-2023
  • 641 Bytes
You can Share it: