Req #46240 [Com]: Build in foreach else support

From: Date: Tue, 10 May 2016 13:54:29 +0000
Subject: Req #46240 [Com]: Build in foreach else support
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200989@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46240&edit=1 ID: 46240 Comment by: valid at email dot ru Reported by: kjarli at gmail dot com Summary: Build in foreach else support Status: Duplicate Type: Feature/Change Request Package: Scripting Engine problem Operating System: * PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: It's funny how such an useful feature gets rejected while they implement junk like foreach-list compatibility and unfinished dereferencing. I usually really like PHP, but this is really low. Previous Comments: ------------------------------------------------------------------------ [2016-05-04 13:26:08] nikic@php.net Related To: Bug #72148 ------------------------------------------------------------------------ [2013-05-14 12:14:18] amseon at web dot de @[2012-10-17 21:44 UTC] php at yopmail dot com Thats true, but you could solve it maybe like this: ------- echo "<ul>"; foreach($data as $item){ echo "<li>$item</li>"; } else { echo "<li>No think to see :(</li>"; } echo "</ul>"; ------- ------------------------------------------------------------------------ [2013-02-04 08:58:41] paul dot cooperman at gmail dot com So like the try catch in .NET? ------------------------------------------------------------------------ [2013-01-04 14:51:50] riccardo dot mastellone at gmail dot com Having the 'else' in case of an empty array would be soo nice, please do add this option! ------------------------------------------------------------------------ [2012-10-17 21:44:33] php at yopmail dot com foreach(){}else{} is a good id but perhaps need to be improved : this simple example can't be converted to foreachElse (due to <ul/>) : ------- if(count($data)>0){ echo "<ul>"; foreach($data as $item){ echo "<ul>$item<ul>"; echo "<ul>"; } else { echo "<p>No think to see :(</p>"; } ------- ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=46240 -- Edit this bug report at https://bugs.php.net/bug.php?id=46240&edit=1

« previous php.bugs (#200989) next »