A lot of the gripes about PHP as a language come down to the fact that there are a million ways to accomplish the same task, but only a couple are truely 'correct' - as in significantly better for one reason or another. Out of all those reasons script efficiency and speed are the driving force behind all experienced programmers. That being said it's hard to know what the right way to do things are. Sure there are 100 ways to do something but all but 2 or 3 of those take an obscene amount of time. Normally, during development, you won't notice long load times because it's not getting hammered by thousands of users requesting the same page.
Chris Vincent has set up The PHP Benchmark to help visually show how some methods are more effecient than others.
PHPBench.com was constructed as a way to open people's eyes to the fact that not every PHP code snippet will run at the same speed.
A few highlights:
<?php
foreach($aHash as $val);
// VS
while(list(,$val) = each($aHash));
?>
- foreach($array as $value) is the fastest way to loop through an array.
- foreach($array as $key => $value) is slightly slower by about 10-15% so use it only when necassary.
- Using while() and for() loops dramatically increases the server load especially when used in conjuction with list() and each().
-Read More