在数组上按值

将元素推送到数组有两种方法:array_push$array[] =

array_push 这样使用:

$array = [1,2,3];
$newArraySize = array_push($array, 5, 6); // The method returns the new size of the array
print_r($array); // Array is passed by reference, therefore the original array is modified to contain the new elements

此代码将打印:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 5
    [4] => 6
)

$array[] = 使用如下:

$array = [1,2,3];
$array[] = 5;
$array[] = 6;
print_r($array);

此代码将打印:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 5
    [4] => 6
)