Don’t Push if you don’t have to!

I learned something new the other day while studying for the PHP 5 Certification exam and when I actually read the docs on php.net for array_push I found the same tip:

Using

$arr[] = “blah”;

is faster than using

array_push($arr, "blah");

Why? because its not doing a function call. Another thing I learned, and a good use of array_push is when you have multiple items to add to the list

array_push($arr, "blah", "crap", "need more coffee");

In that case, I think it may be faster to do that then to do a for loop and add the 3 items individually.

Just a little something I thought I’d pass along .. :)

Leave a Comment