php array_unshift() function
Translation results:
UK [ʌn'ʃɪft] US [ʌn'ʃɪft]
vi. Release the font change key on the typewriter or keyboard
php array_unshift() functionsyntax
Function: Used to insert new elements into the array. The values of the new array will be inserted at the beginning of the array.
Syntax: array_unshift(array,value1,value2,value3...)
Parameters:
Parameters | Description |
array | Required. Specifies an array. |
value1 | Required. Specifies the value to be inserted. |
value2 | Optional. Specifies the value to be inserted. |
value3 | Optional. Specifies the value to be inserted. |
Explanation: The added elements are added as a whole, and the order of these elements in the array is the same as the order in the parameters. This function returns the number of elements in the array. You can insert one or more values. Numeric key names will start at 0 and increase by 1. String key names will remain unchanged.
php array_unshift() functionexample
<?php $a=array("a"=>"西门","b"=>"灭绝"); print_r(array_unshift($a,"无忌")); echo "<br>"; print_r($a); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
3 Array ( [0] => 无忌 [a] => 西门 [b] => 灭绝 )
<?php $a=array("a"=>"欧阳克","b"=>"西门"); print_r(array_unshift($a,"peter_zhu")); //返回数组长度 echo "<br>"; print_r($a); //输出新的数组 ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
3 Array ( [0] => peter_zhu [a] => 欧阳克 [b] => 西门 )