Req #61222 [Opn]: For... else construct

From: Date: Thu, 01 Mar 2012 15:42:43 +0000
Subject: Req #61222 [Opn]: For... else construct
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-167967@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61222&edit=1 ID: 61222 User updated by: jeroenvandenenden at gmail dot com Reported by: jeroenvandenenden at gmail dot com Summary: For... else construct Status: Open Type: Feature/Change Request Package: Arrays related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Of course instead of for ($val in $array) { I meant foreach ($array as $val) { Previous Comments: ------------------------------------------------------------------------ [2012-03-01 15:27:36] 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'; } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61222&edit=1

« previous php.bugs (#167967) next »