Syntax:array array_splice ($array1, $start_point, $range, $array2)
Parameters:this function can take four parameters and is described below:
$array1 (required):this parameter refers to the original array with which we want to work. $start_point (required):this parameter refers to the starting position of the array from which you want to remove elements. Be sure to include this value. If the supplied value is negative, then the function starts deleting from the end of the array, that is, -1 refers to the last element of the array. $range (optional):this parameter refers to a range, or the limiting point to which the deletion must be performed. A negative value will indicate the amount from the end of the line. This can now also be left blank. If you leave the field blank, the function will delete all values specified at the start point up to the end. $array2 (optional):this refers to another array whose elements are to be inserted into $array1. Now, to insert a single element, we don’t need to provide the entire array. We can just pass one string for one value. For a group of values, we need an array. Returned value:the function will return an array of deleted elements from $start_point to $range.Below is the program illustrates the array_splice() function in PHP:
// PHP program to illustrate usage
// array_splice() functions
$array1
=
array
(
"10"
= >
" raghav "
,
" 20 "
= >
"ram"
,
" 30 "
= >
"laxman"
,
"40"
= >
"aakash"
,
" 50 "
= >
" ravi "
);
$array2
=
array
(
" 60 "
= >
"ankita"
,
"70"
= >
"antara"
);
echo
" The returned array: "
;
print_r (
array_splice
( $array1
, 1, 4,
$array2
));
echo
" The original array is modified to: "
;
print_r (
$array1
);
?>
Output:The returned array : Array ([0] = > ram [1] = > laxman [2] = > aakash [3] = > ravi) The original array is modified to: Array ([0] = > raghav [1 ] = > ankita [2] = > antara)
Link :
http://php.net/manual/en/function.array-splice.php