1$myArr = [1, 2, 3, 4];
2
3array_push($myArr, 5, 8);
4print_r($myArr); // [1, 2, 3, 4, 5, 8]
5
6$myArr[] = -1;
7print_r($myArr); // [1, 2, 3, 4, 5, 8, -1]
1$items = array();
2foreach($group_membership as $username) {
3 $items[] = $username;
4}
5
6print_r($items);
1$fruits = ["apple", "banana"];
2// array_push() function inserts one or more elements to the end of an array
3array_push($fruits, "orange");
4
5// If you use array_push() to add one element to the array, it's better to use
6// $fruits[] = because in that way there is no overhead of calling a function.
7$fruits[] = "orange";
8
9// output: Array ( [0] => apple [1] => banana [2] => orange )
1$array[$key] = $value;
2// or
3$array[] = $value;
4// or
5array_push($array, [ mixed $... ]);
1PHP function array_push(array &$array, ...$values) int
2------------------------------------------------------
3Push elements onto the end of array. Since 7.3.0 this function can be called with only one parameter.
4For earlier versions at least two parameters are required.
5
6Parameters:
7array--$array--The input array.
8mixed--...$values--[optional] The pushed variables.
9
10Returns: the number of elements in the array.