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

  1. <?php
  2.  
  3.  
  4. $array = ['element 1', 'element 2', 'element 3', 'element 4', 'element 5', 'element 6'];
  5.  
  6. $template_count = 3;//сколько разных типов блоков
  7. $i=1;
  8. foreach($array as $item){
  9.     
  10.     if($i == 1){
  11.         echo "первый тип: " . $item . "\r";
  12.     }
  13.     
  14.     if($i == 2){
  15.         echo "второй тип: " . $item . "\r";
  16.     }
  17.     
  18.     
  19.     if($i == 3){
  20.         echo "третий тип: " . $item . "\r";
  21.     }
  22.     
  23.     
  24.     
  25.     //увеличиваем переменную или сбрасываем
  26.     if($i >= $template_count){
  27.         $i = 1;
  28.     }else{
  29.         $i = $i+1;
  30.     }
  31.    
  32. }
File Description
  • test
  • PHP Code
  • 25 Oct-2019
  • 633 Bytes
You can Share it: