Задача 2 - 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 Задача 2.php

  1. <?php
  2. $numbers = range(1, 1000);
  3. shuffle($numbers);
  4. $chunkedNumbers = array_chunk($numbers, 5);
  5. $result = array_splice($chunkedNumbers, 0, 7);
  6. foreach ($result as $row) {
  7.     foreach($row as $el) {
  8.         echo $el . " ";
  9.     }
  10.     echo "\n";
  11. }
  12.  
  13.  
  14. $columnsSums = [];
  15. for ($i=0;$i<=4;$i++) {
  16.     $columnsSums[$i] = array_sum(array_column($result, $i));
  17. }
  18. echo "\nСуммы по столбцам: ";
  19. print_r(implode(' ', $columnsSums));
  20.  
  21.  
  22. $rowsSums = [];
  23. foreach($result as $row) {
  24.     $rowsSums[] = array_sum($row);
  25. }
  26. echo "\nСуммы по строкам: ";
  27. print_r(implode(' ', $rowsSums));
  28.  
File Description
  • Задача 2
  • PHP Code
  • 26 Aug-2022
  • 594 Bytes
You can Share it: