to add one element to an array the function is twice as slowly as the operator.

Posted by Ralph Schindler (ralph) on 2009-01-29T10:33:40.000+0000

This is not a performance issue. The performance difference between [] and array_push is negligible at best and both methods are valid for different reasons.

Bracket notation is useful for adding values to a variable (whether it has been initialized as an array or not). $i = null; $i[] = 'foo'; will not throw a notice, where as array_push($i, 'foo') will throw a E_WARN that the first argument must be an array.

Also, array_push() will return the count of all the elements which in some situations might be useful. Ultimately, its up to the component developer which method better suites the needs of the component.