Created
June 21, 2023 14:33
-
-
Save SitesByYogi/54c0fbf2759dc0c9ebd0ce347184d43a to your computer and use it in GitHub Desktop.
PHP Loops
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 | |
// 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