ID:               46240
 Comment by:       john at brahy dot com
 Reported By:      kjarli at gmail dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.2.6
 New Comment:

Please add a foreach else. It would save so much programming time and
eliminate so much room for error. It's so simple... foreach (){} else
{}

PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE


Previous Comments:
------------------------------------------------------------------------

[2008-10-06 08:57:14] kjarli at gmail dot com

Description:
------------
Each time you want to foreach an array, you first have to check with 
a count or empty if you want to give a message or w/e to notify there 
is no entry to an array (or object if implements like iterator).

If possible add a else option to foreach.




Reproduce code:
---------------
<?php // old style
if(count($myArray) > 0) {
    foreach($myArray as $key => $value) {
    }
}

//new style

foreach($myArray as $key => $value) {
} else {
   // empty array/object
}
(kinda like how smarty implements it)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46240&edit=1

Reply via email to