DEV Community

Jitendra
Jitendra

Posted on

PHP loop patterns

Some patterns created with (nested) loops. Please comment if you have any.

Code:

for ($i = 0; $i < 10; $i++) { for ($j = 0; $j < 10; $j++) { if (in_array($j, [0, 9, $i]) || in_array($i, [0, 9, 9 - $j])) { echo "#"; } else { echo ' '; } } echo "\n"; } 
Enter fullscreen mode Exit fullscreen mode

Output:

########## ## ## # # # # # # # # # ## # # ## # # # # # # # # # ## ## ########## 
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
kushal-niroula profile image
Kushal Niroula

Not strictly a pattern , also not something I made. I saw this somewhere once, I just cant seem to remember where (If its yours, please inform me).

$i = 0; while($i < 3) { printf("%c", 73 + $i * $i * 3); $i++; } 

This script prints ILU <3

Collapse
 
adhocore profile image
Jitendra

not mine. just seeing this. i assume it is public domain somewhere.

Collapse
 
pkristiancz profile image
Patrik Kristian • Edited

lol i was looking on phone, and i guessed it right

thepracticaldev.s3.amazonaws.com/i...

Collapse
 
adhocore profile image
Jitendra

funny 😁