Parameter instance
Insert "blue" and "yellow" to the tail of the array:
<?php$a=array ("Red", "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >
Definition and usage
The Array_push () function inserts one or more elements into the tail of the array.
Tip: You can add one or more values.
Note: Even if your array has a string key name, the element you are adding will be a numeric key name (see the following example).
Grammar
Array_push (Array,value1,value2 ...)
parameters |
description |
array |
required. Specifies an array. |
value1 |
required. Specifies the value to add. |
value2 |
optional. Specifies the value to add. |
Technical details
return value: |
Returns the number of elements of the new array. |
PHP version: |
4 + |
More examples
Example 1
An array with the string key name:
<?php$a=array ("A" and "Red", "b" = "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >
Example One
Use the PHP Array_push () function to insert "blue" and "yellow" at the end of the array with the following code:
<?php$a=array ("Red", "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >
Code Run Result: