|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-03-01 15:27 UTC] jeroenvandenenden at gmail dot com
Description:
------------
It would be nice to have a for...else construct like you see in other languages.
This makes the code more compact and readable and it avoids the necessity to
combine an if and a for loop.
Test script:
---------------
for ($val in $array) {
echo $val.'<br />';
} else {
echo 'No values found';
}
Expected result:
----------------
In the case of an empty array, the else part would be called. Without this
construct the code would be as follows.
if (count($array) > 0) {
for ($val in $array) {
echo $val.'<br />';
}
} else {
echo 'No values found';
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
Of course instead of for ($val in $array) { I meant foreach ($array as $val) {There are already bugs for foreach { } else { } and while { } else { }, both highly rated. I think this should be all consolidated into a single bug or an RFC, or it will never get done.