[development] Note that PHP arrays are fast

Jakob Petsovits jpetso at gmx.at
Tue Apr 10 06:20:37 UTC 2007


On Tuesday, 10. April 2007, Karoly Negyesi wrote:
> Hi,
>
> Note my trick in http://drupal.org/node/134697 which shows that the hash
> lookups in Zend Engine are a bit faster than branching.
>
> Instead of
>
>    $class = $class == 'even' ? 'odd' : 'even'
>
> we have
>
>    $flip = array('even' => 'odd', 'odd' => 'even');
>    $class = $flip[$class];

Just out of interest, what's with

if ($class !== 'even') {
    $class = 'odd';
}

?
Wouldn't this avoid half the assignments and replace the other half with a 
simple check (while making the code still a bit more readable)?

Maybe there's some optimization magic that I don't know of, though.

Regards,
  Jakob


More information about the development mailing list