RosettaCodeData/Task/Identity-matrix/PHP/identity-matrix.php
2023-07-01 13:44:08 -04:00

8 lines
346 B
PHP

function identity($length) {
return array_map(function($key, $value) {$value[$key] = 1; return $value;}, range(0, $length-1),
array_fill(0, $length, array_fill(0,$length, 0)));
}
function print_identity($identity) {
echo implode(PHP_EOL, array_map(function ($value) {return implode(' ', $value);}, $identity));
}
print_identity(identity(10));