Difference between array_push() and $array[] =

前端 未结 9 2068
梦毁少年i
梦毁少年i 2020-12-02 07:06

In the PHP manual, (array_push) says..

If you use array_push() to add one element to the array it\'s better to use $array[]

9条回答
  •  执念已碎
    2020-12-02 07:41

    The difference is in the line below to "because in that way there is no overhead of calling a function."

    array_push() will raise a warning if the first argument is not an array. This differs from the $var[] behaviour where a new array is created.

提交回复
热议问题