Re: For ... <= max($myArray) vs For ... <= $max

From: Date: Fri, 08 Nov 2002 12:12:00 +0000
Subject: Re: For ... <= max($myArray) vs For ... <= $max
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123359@lists.php.net to get a copy of this message
As max($myArray) may potentionaly change, it is evalueted everytime (you may do $myArray[]=$big_number in your loop). So if you know it is not going to change, use the first way. Daevid Vincent wrote:
Is PHP smart enough to optimize loops? That is, are these two 'for...loops' equivalent or is one slower than the other? $max = max($myArray); for( $x = 1; $x <= $length; $x++ ) {} -- OR -- for( $x = 1; $x <= max($myArray); $x++ ) {} My gut instinct tells me since PHP is interpreted, that the top one is the better way to go, but with the Zend Optimizer, I don't know if PHP handles them the same way or not?


« previous php.general (#123359) next »