Am 25.02.2020 um 20:18 schrieb Michael Morris <tendo...@gmail.com>: > How difficult would it be to make the following work in the interpreter? > > <?php > foreach($a as $key => $value) { > // code for iteration > } > else { > // code for no results > } > ?> > > The code of the else clause executes if the foreach is never entered > regardless of the reason (provided the code didn't outright crash)
I like the idea. And I think it makes more sense than what Python actually does: With Python the else clause is executed if the loop is not exited with a break. https://book.pythontips.com/en/latest/for_-_else.html So, yes, I would like a foreach .. else but not the Python way ;-) - Chris -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php