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

前端 未结 10 1168
野性不改
野性不改 2020-12-02 01:28

What\'s better to use in PHP for appending an array member,

$array[] = $value;

or

array_push($array, $value);
10条回答
  •  庸人自扰
    2020-12-02 02:13

    The main use of array_push() is that you can push multiple values onto the end of the array.

    It says in the documentation:

    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.

提交回复
热议问题