Anonymous user
Identity matrix: Difference between revisions
→{{header|PHP}}
m (→{{header|AppleScript}}: tidied, updated output.) |
|||
Line 2,409:
=={{header|PHP}}==
<lang php>
function
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));
</lang>
{{out}}
<pre>
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
</pre>
|