Головоломка - 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 Головоломка.php

  1. <?php
  2. $collectionDivElements = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
  3. outputBlocks($collectionDivElements);
  4.  
  5. function outputBlocks(array $collectionDivElements)
  6. {
  7.     $iBlock=1;
  8.     for($i=1; $i<=count($collectionDivElements); $i++){
  9.         $element =  $collectionDivElements[$i-1];
  10.         if(($i % 2) != 0){
  11.             echo <<<ONE
  12. <div строка$iBlock>
  13. <div> элемент $element </div>
  14. ONE;
  15.         }
  16.         else{
  17.             echo <<<TWO
  18. \n<div> элемент $element </div>
  19. </div>\n
  20. TWO;
  21.             $iBlock++;
  22.         }
  23.     }
  24. }
  25.  
File Description
  • Головоломка
  • PHP Code
  • 26 May-2023
  • 547 Bytes
You can Share it: