UK[splaɪs] 美[splaɪs]
vt. splicing; twisting (two sections of rope); gluing; bonding (film, tape, etc.)
n. Glue Joint, bonding, hinge
Third person singular: splices Present participle: splicing Past tense: spliced Past participle: spliced
php array_splice() function syntax
Function:Remove the selected element from the array and replace it with a new element.
Syntax: array_splice(array,start,length,array)
Parameters:
Parameters | Description |
array | Required. Specifies an array. |
start | Required. numerical value. Specifies the starting position of deleted elements. 0 = first element. If the value is set to a positive number, removal begins at the offset in the array specified by the value. If the value is set to a negative number, removal begins at the offset specified by the value from the end of the array. -2 means start from the second to last element of the array. |
length | Optional. numerical value. Specifies the number of elements to be removed, which is also the length of the returned array. If the value is set to a positive number, that number of elements are removed. If this value is set to a negative number, all elements from start to length inverse of the end of the array are removed. If this value is not set, all elements from the position set by the start parameter to the end of the array are removed. |
array | Optional. Specifies the array with the elements to be inserted into the original array. If there is only one element, it can be set to a string and does not need to be set to an array. |
Description: Selects a series of elements in the array, but does not return them, but deletes them and replaces them with other values. If a fourth argument is provided, those previously selected elements will be replaced by the array specified by the fourth argument. The final generated array will be returned.
php array_splice() function example
<?php $a1=array("a"=>"男友","b"=>"老公","c"=>"手机","d"=>"口红"); $a2=array("眼影","护肤品"); array_splice($a1,0,2,$a2); print_r($a1); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
Array ( [0] => 眼影 [1] => 护肤品 [c] => 手机 [d] => 口红 )