PHP Performance

I have some more PHP Performance notes somewhere, but this is all that I can find right now.

  • Use for loops over foreach loops
  • Use ‘ over “, unless you are parsing variables
  • Use echo over print

For Loops
Use either of the following syntax for your for loops. They take about the same amount of time to execute

$count = count($arr);
for ($i = 0; $i < $count; $i++) { }
 
for ($i = 0, $count = count($arr); $i < $count; $i++) { }

DO NOT use the following, it is significantly slower:

for ($i = 0; $i < $count($arr); $i++) { }

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">