push() vs. $array[] = .... Which is fastest?

This question already has an answer here:

  • What's better to use in PHP $array[] = $value or array_push($array, $value)? 10 answers

  • u can run and see that array_push is slower in some case

    http://snipplr.com/view/759/speed-test-arraypush-vs-array/

    run your code . enjoy


    Depends...

    Documentation says ,

    "If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function."

    Source: http://us2.php.net/array_push

    So it boils down to how much data you want to cram into that array at any particular moment. Additionally, there's a fall-back, if the array-referenced doesn't exist when you call it using array_push, you'll bump an error. If you use $array[], the array will be created for you.

    链接地址: http://www.djcxy.com/p/59402.html

    上一篇: 哪个更快$ variable []或数组

    下一篇: push()与$ array [] = ....哪个最快?