<?php
// Insert "blue" and "yellow" to the end of an array:
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
$array[$key] = $value;
// or
$array[] = $value;
// or
array_push($array, [ mixed $... ]);
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
?>
array_push($array,$value);
// The array_push() function inserts one or more elements to the end of an array.
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
array_push ( array &$array [, mixed $... ] ) : int
or
$array[] = $var;
// array_push ( array &$array [, mixed $... ] ) : int
// array_push() treats array as a stack, and pushes the passed variables onto the end of array. The length of array increases by the number of variables pushed. Has the same effect as:
<?php
$array[] = $var;
?>
// repeated for each passed value.
// Note: 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.
If you're going to use array_push() to insert a "$key" => "$value" pair into an array, it can be done using the following:
$data[$key] = $value;
It is not necessary to use array_push.
PHP function array_push(array &$array, ...$values) int
------------------------------------------------------
Push elements onto the end of array. Since 7.3.0 this function can be called with only one parameter.
For earlier versions at least two parameters are required.
Parameters:
array--$array--The input array.
mixed--...$values--[optional] The pushed variables.
Returns: the number of elements in the array.
Code Example |
---|
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
Javascript :: |
:: |
:: |
:: |
:: |
:: |
:: |