Usage and definition of array_push () function for php array operation functions. A simple array_push () function is a commonly used function for Array Operations. if you need it, refer to (PHP4, PHP5) array_push uses a simple array_push () function for one or more units. this is a commonly used function for Array Operations. if you need it, please refer to it.
(PHP 4, PHP 5)
Array_push-push one or more units to the end of the array (into the stack)
Report a bug description
Int array_push (array & $ array, mixed $ var [, mixed $...])
Array_push () treats array as a stack and pushes the passed variables to the end of array. The length of array increases according to the number of variables in the stack. The effect is the same as the following:
| The code is as follows: |
|
$ Array [] = $ var;
?>
|
Repeat the preceding actions for each var.
Returns the total number of new units in the array.
Example 1
| The code is as follows: |
|
$ A = array ("Dog", "Cat ");
Array_push ($ a, "Horse", "Bird ");
Print_r ($ );
?> |
Output:
Array ([0] => Dog [1] => Cat [2] => Horse [3] => Bird) Example 2
Arrays with string keys:
| The code is as follows: |
|
$ A = array ("a" => "Dog", "B" => "Cat ");
Array_push ($ a, "Horse", "Bird ");
Print_r ($ );
?> |
Output:
Array ([a] => Dog [B] => Cat [0] => Horse [1] => Bird)
Note: If array_push () is used to add a unit to the array, it is better to use $ array [] =, because there is no additional burden to call the function.
Note: If the first parameter is not an array, array_push () will issue a warning. This is different from the behavior of $ var []. The latter creates an array.
See array_pop (), array_shift (), and array_unshift ().
If you want to preserve the keys in the array, use the following:
| The code is as follows: |
|
|
Function array_pshift (& $ array ){
$ Keys = array_keys ($ array );
$ Key = array_shift ($ keys );
$ Element = $ array [$ key];
Unset ($ array [$ key]);
Return $ element;
}
?> |
Evaluate () function usage. this is a commonly used function for Array Operations. For more information, see (PHP 4, PHP 5) array_push will put one or more units...