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";
$cellMatrix = [];
foreach ($matrix as $matrixRow) {
$preparedMatrixRow = array_map(function($number){
return sprintf("%' 6d", $number);
}, $matrixRow);
$rowString = implode(" | ", $preparedMatrixRow);
$rowSumm = array_sum($matrixRow);
echo " | $rowString | $rowSumm\n";
foreach ($matrixRow as $keymr => $val) {
$cellMatrix[$keymr] = isset($cellMatrix[$keymr]) ? $cellMatrix[$keymr] + $val : $val;
}
}
// var_dump($cellMatrix);
$preparedMatrixLastRow = array_map(function($number){
return sprintf("%' 6d", $number);
}, $cellMatrix);
$rowString = implode(" | ", $preparedMatrixLastRow);
echo " summ | $rowString | \n";