Last active
April 10, 2025 22:07
-
-
Save edutrul/9e0a97ec72c6059f527db4933fd9e5c0 to your computer and use it in GitHub Desktop.
Session 04 - Loops and Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$movies = [ | |
'Harry Potter I', | |
'Star Wars V', | |
'One Piece movie', | |
'Titanic', | |
'Frozen III', | |
'Exorcista 2025', | |
]; | |
print $movies[0] . "\n"; | |
print $movies[1] . "\n"; | |
print $movies[2] . "\n"; | |
print "\n\n"; | |
print 'Foreach' . "\n"; | |
foreach ($movies as $movie) { | |
print $movie . "\n"; | |
} | |
print "\n\n"; | |
print 'For' . "\n"; | |
for ($i = 0; $i < count($movies); $i++) { | |
print $movies[$i] . "\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print 'Ciclos repetitivos' . "\n"; | |
print 'Example with while:' . "\n"; | |
$counter = 0; | |
while ($counter < 2) { | |
print 'something ' . $counter . "\n"; | |
$counter++; | |
} | |
print "\n\n"; | |
print 'Example with for statement:' . "\n"; | |
for ($i = 0; $i < 9; $i++) { | |
// Strict comparison. | |
if ($i % 2 !== 0) { | |
print 'something ' . $i . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment