Created
August 7, 2020 11:45
-
-
Save tuanpt-0634/9df885d41b2dd73a5c6f03597fc40dc7 to your computer and use it in GitHub Desktop.
Foreach Try Inline
This file contains 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 | |
$options = [1, 2, 3]; | |
foreach ($options as $option) try { | |
if ($option == 2) { | |
throw new \Exception('2 is missing!!'); | |
} | |
echo $option . PHP_EOL; | |
} catch (\Exception $ex) { | |
echo "Exception: ", $ex->getMessage(), "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment