Source Code:
(back to article)
<?php function getList() { // Assume some error occurs here and instead of // a list/array, a boolean FALSE is returned. return false; } // Get the array from a function call. $myList = getList(); // Check if $myList is indeed an array or an object. if (is_iterable($myList)) { // If yes, then foreach() will iterate over it. foreach ($myList as $arrayItem) { //Do something. } } // If $myList was not an array, then this block is executed. else { echo "Unfortunately, an error occurred."; } ?>
Result:
Report an issue