note 46540 deleted from control-structures.foreach by tomsommer

From: Date: Thu, 14 Oct 2004 21:13:41 +0000
Subject: note 46540 deleted from control-structures.foreach by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78555@lists.php.net to get a copy of this message
Note Submitter: jimmy dot hansen at gmail dot com ---- In response to dual iteration using a for instead of foreach (andy at barbigerous dot net, endofyourself at yahoo dot com): The while evaluation of your for loop will break only if the last expression in it returns false when using commas instead of &&/AND*. <?PHP // This will continue until list(,$val1) = each($arr1) is false for( ; false , list(,$val1) = each($arr1) ; ) // This will break immediately for( ; list(,$val1) = each($arr1) , false ; ) // Here is your original example for( $someArray1.reset(), $someArray2.reset(); list(, $someValue1 ) = each( $someArray1 ) , list(, $someValue2 ) = each( $someArray2 ) ; ) // This will produce expected results for( $someArray1.reset(), $someArray2.reset(); list(, $someValue1 ) = each( $someArray1 ) && list(, $someValue2 ) = each( $someArray2 ) ; ) ?> The one situation where you would want to use a comma is if you wanted to continue iterating until only your last condition returned false, but this circumstance is rare. * If using AND, be sure to enclose each condition in parenthesis since && will evaluate before the assigment operator (=) and AND after. ---- Reason: useless note

« previous php.notes (#78555) next »