| Conditions | 4 |
| Paths | 4 |
| Total Lines | 33 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 76 | private static function printMatrixCli($matrix) |
||
| 77 | { |
||
| 78 | system('clear'); |
||
| 79 | $colors = [ |
||
| 80 | "0;34", |
||
| 81 | "0;32", |
||
| 82 | "0;36", |
||
| 83 | "0;31", |
||
| 84 | "0;35", |
||
| 85 | "0;33", |
||
| 86 | "0;37", |
||
| 87 | "1;30", |
||
| 88 | "1;34", |
||
| 89 | "1;32", |
||
| 90 | "1;36", |
||
| 91 | "1;31", |
||
| 92 | "1;35", |
||
| 93 | "1;33", |
||
| 94 | "1;37" |
||
| 95 | ]; |
||
| 96 | |||
| 97 | for ($i = 0; $i < sizeof($matrix); $i++) { |
||
|
|
|||
| 98 | $out = implode($matrix[$i]) . "\n"; |
||
| 99 | for ($k = 0; $k < strlen($out); $k++) { |
||
| 100 | if ($out[$k] > 0) { |
||
| 101 | $colorNumber = $out[$k] % 16; |
||
| 102 | echo "\033[" . $colors[$colorNumber] . "m" . $out[$k] . "\033[0m"; |
||
| 103 | } else { |
||
| 104 | echo $out[$k]; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | usleep(100000); |
||
| 109 | } |
||
| 111 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: