Source Code:
(back to article)
<?php // Define an array with some values $array = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "indigo", "jackfruit", "kiwi", "lemon"]; // Loop through the first 10 items of the array and output their values $counter = 0; foreach ($array as $item) { if ($counter == 4) { break; } echo $item . "\n"; $counter++; } // Output: apple // banana // cherry // date
Result:
Report an issue