Posted by Ralph Schindler (ralph) on 2009-01-10T09:38:10.000+0000
Whats the issue here? The usage of one or the other has always been a negligible difference. Please add more commentary as to what you are advocating.
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2009-01-29T01:45:42.000+0000
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.
Comments
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2009-01-08T09:54:59.000+0000
bechmark:
output:
Posted by Ralph Schindler (ralph) on 2009-01-10T09:38:10.000+0000
Whats the issue here? The usage of one or the other has always been a negligible difference. Please add more commentary as to what you are advocating.
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2009-01-29T01:45:42.000+0000
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.