php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27612 "else" statement for "foreach" construct
Submitted: 2004-03-16 04:05 UTC Modified: 2012-09-22 09:29 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: camka at email dot ee Assigned:
Status: Duplicate Package: *General Issues
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: camka at email dot ee
New email:
PHP Version: OS:

 

 [2004-03-16 04:05 UTC] camka at email dot ee
Description:
------------
"else" statement would be very useful and comfortable when the array_expression in foreach construct is empty. There'd be no need to calculate count(array) every time you need to execute some code in case of empty array. 
Smarty has such syntax and it really helps.

Reproduce code:
---------------
$count = count($array);

foreach($array as $arr)
{
...
}

if(!$count)
{
...
}

===============================

foreach($array as $arr)
{
...
}
else //may be [foreachelse] or [elseforeach]
{
...
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 09:29 UTC] nikic@php.net
Closing as duplicate of https://bugs.php.net/bug.php?id=26411.
 [2012-09-22 09:29 UTC] nikic@php.net
-Status: Open +Status: Duplicate -Package: Feature/Change Request +Package: *General Issues
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 14:01:30 2024 UTC