I don't remember if this has been discussed before, but I've been working
with some listing code and wishing for a cleaner way to do this

<?php
  if (count($a) === 0) {
    // code for no results
  }
  else {
    foreach( $a as $key => $value) {
      // code for iteration
    }
  }
?>

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)

Thoughts.

Reply via email to