| Conditions | 4 |
| Paths | 4 |
| Total Lines | 33 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | private static function printMatrixCli($matrix) |
||
| 37 | { |
||
| 38 | system('clear'); |
||
| 39 | $colors = [ |
||
| 40 | "0;34", |
||
| 41 | "0;32", |
||
| 42 | "0;36", |
||
| 43 | "0;31", |
||
| 44 | "0;35", |
||
| 45 | "0;33", |
||
| 46 | "0;37", |
||
| 47 | "1;30", |
||
| 48 | "1;34", |
||
| 49 | "1;32", |
||
| 50 | "1;36", |
||
| 51 | "1;31", |
||
| 52 | "1;35", |
||
| 53 | "1;33", |
||
| 54 | "1;37" |
||
| 55 | ]; |
||
| 56 | |||
| 57 | for ($i = 0; $i < sizeof($matrix); $i++) { |
||
|
|
|||
| 58 | $out = implode($matrix[$i]) . "\n"; |
||
| 59 | for ($k = 0; $k < strlen($out); $k++) { |
||
| 60 | if ($out[$k] > 0) { |
||
| 61 | $colorNumber = $out[$k] % 16; |
||
| 62 | echo "\033[" . $colors[$colorNumber] . "m" . $out[$k] . "\033[0m"; |
||
| 63 | } else { |
||
| 64 | echo $out[$k]; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | usleep(100000); |
||
| 69 | } |
||
| 71 | } |
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: