To join an array in PHP, we have a ready-to-use function, which is the Array_splice () function, which removes all elements from offset to end of offset+length in the array and returns the deleted element as an array. The Array_splice () syntax format is:
Array array_splice (array array, int Offset[,length[,array replacement])
When offset is positive, the join starts at offset from the beginning of the array, and when offset is negative, the join starts at the offset position from the end of the array. If the optional length parameter is omitted, all elements from the offset position to the end of the array are deleted. If length is given and positive, the join ends at offset + Leng th at the beginning of the array. Conversely, if length is given and is negative, the union ends at the position of Count (Input_array)-length from the beginning of the array.
To see an example of a standard junction array, PHP code:
1
2$fruits = Array ("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "watermelon");
3$subset = Array_splice ($fruits, 4);
4print_r ($fruits);
5print_r ($subset);
The 6//output results are:
7//Array ([0] = Apple [1] = Banana [2] = Orange [3] = Pear)
8//Array ([0] = Grape [1] = Lemon [2] = watermelon)
9?>
We can also use the optional parameter replacement to specify an array that supersedes the target part. Take a look at the following example:
1
2$fruits = Array ("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "watermelon");
3$subset = Array_splice ($fruits, 2,-1, Array ("Green Apple", "Red Apple"));
4print_r ($fruits);
5print_r ($subset);
6//Output Results:
7//Array ([0] = Apple [1] = Banana [2] + Green Apple [3] + Red Apple [4] = watermelon)
8//Array ([0] = Orange [1] = Pear [2] = = Grape [3] = Lemon)
9?>
http://www.bkjia.com/PHPjc/765440.html www.bkjia.com true http://www.bkjia.com/PHPjc/765440.html techarticle To join an array in PHP, we have a ready-made function that can be used, which is the Array_splice () function, which removes all elements from offset start to offset+length end in the array, and takes the array of ...