Guest User

Untitled

a guest
Jan 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. <?php
  2.  
  3. function minhaMatriz($cols = 5)
  4. {
  5. $data = array_fill(0, $cols, array_fill(0, $cols, 0));
  6.  
  7. foreach($data as $i => $items) {
  8. foreach($items as $j => $item) {
  9. if ($i == $j || $i == 0) {
  10. $data[$j][$i] = 1;
  11. } else {
  12. $data[$j][$i] = $item;
  13. }
  14. }
  15. }
  16.  
  17. return $data;
  18. }
  19.  
  20. foreach(minhaMatriz() as $items) {
  21. foreach($items as $item) {
  22. echo $item;
  23. }
  24.  
  25. echo "\n";
  26. }
  27.  
  28. /*
  29. Default(5):
  30.  
  31. 1 0 0 0 0
  32. 1 1 0 0 0
  33. 1 0 1 0 0
  34. 1 0 0 1 0
  35. 1 0 0 0 1
  36. */
Add Comment
Please, Sign In to add comment