php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65298 foreach/else
Submitted: 2013-07-19 18:40 UTC Modified: 2013-07-19 20:17 UTC
From: john at brahy dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
 [2013-07-19 18:40 UTC] john at brahy dot com
Description:
------------
I am requesting a feature for php. It's adding an else statement to a foreach loop 
that would be executed when there are no elements to iterate over. 


foreach ( $rows as $row ) {
 print $row;
} else {
 print "<tr><td>No Data</td></tr>";
}






Test script:
---------------
foreach ( $rows as $row ) {
 print $row;
} else {
 print "<tr><td>No Data</td></tr>";
}


Expected result:
----------------
when there is no data in the foreach loop it would execute the else


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-19 20:17 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2013-07-19 20:17 UTC] nikic@php.net
Closing as duplicate of https://bugs.php.net/bug.php?id=26411.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jan 17 23:01:24 2019 UTC