The first one is better, and, besides that - it is the most correct way
- there might be something making the array change while inside the loop
- thus you have to do some extremely high calculations to understand the
array does not change runtime, which makes it useless.
    
Simply do the "elegant programming" and you will never have these issues. 


--
Maxim Maletsky
[EMAIL PROTECTED]



"Ford, Mike               [LSS]" <[EMAIL PROTECTED]> wrote... :

> > -----Original Message-----
> > From: Daevid Vincent [mailto:daevid@;daevid.com]
> > Sent: 08 November 2002 11:13
> > 
> > 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?
> 
> With bare PHP, yes the first one is quicker.  Don't know if the Zend Optimiser 
>changes that.
> 
> Cheers!
> 
> Mike
> 
> ---------------------------------------------------------------------
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to