Skip to content

Instantly share code, notes, and snippets.

@edutrul
Last active April 10, 2025 22:07
Show Gist options
  • Save edutrul/9e0a97ec72c6059f527db4933fd9e5c0 to your computer and use it in GitHub Desktop.
Save edutrul/9e0a97ec72c6059f527db4933fd9e5c0 to your computer and use it in GitHub Desktop.
Session 04 - Loops and Arrays
<?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";
}
<?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