Skip to content

Instantly share code, notes, and snippets.

@SitesByYogi
Created June 21, 2023 14:33
Show Gist options
  • Save SitesByYogi/54c0fbf2759dc0c9ebd0ce347184d43a to your computer and use it in GitHub Desktop.
Save SitesByYogi/54c0fbf2759dc0c9ebd0ce347184d43a to your computer and use it in GitHub Desktop.
PHP Loops
<?php
// Loop through an array
$fruits = array("apple", "banana", "orange");
foreach ($fruits as $fruit) {
echo $fruit . "<br>";
}
// Perform a specific number of iterations
for ($i = 1; $i <= 10; $i++) {
echo $i . "<br>";
}
// Execute code until a condition is met
$counter = 1;
while ($counter <= 5) {
echo "Count: " . $counter . "<br>";
$counter++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment