Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$row = 5;
$cell = 7;
$numArray = range(1, 1000);
shuffle($numArray);
$length = $cell * $row;
$matrix = array_slice($numArray, 0, $length);
$matrix = array_chunk($matrix, $cell);
$lineArray = array_fill(1, $cell, " ");
$firstString = implode(" | ", $lineArray);
echo " | $firstString | summ\n";
echo "----- | $firstString | -----\n";
foreach ($matrix as $matrixRow) {
$preparedMatrixRow = array_map(function($number){
return sprintf("%' 4d", $number);
}, $matrixRow);
$rowString = implode(" | ", $preparedMatrixRow);
$rowSumm = array_sum($matrixRow);
echo " | $rowString | $rowSumm\n";
}
echo " summ | $firstString | \n";