Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function minhaMatriz($cols = 5)
- {
- $data = array_fill(0, $cols, array_fill(0, $cols, 0));
- foreach($data as $i => $items) {
- foreach($items as $j => $item) {
- if ($i == $j || $i == 0) {
- $data[$j][$i] = 1;
- } else {
- $data[$j][$i] = $item;
- }
- }
- }
- return $data;
- }
- foreach(minhaMatriz() as $items) {
- foreach($items as $item) {
- echo $item;
- }
- echo "\n";
- }
- /*
- Default(5):
- 1 0 0 0 0
- 1 1 0 0 0
- 1 0 1 0 0
- 1 0 0 1 0
- 1 0 0 0 1
- */
Add Comment
Please, Sign In to add comment