This inbuilt function of PHP is an advanced and extended version of array_slice() function, where we not only can remove elements from an array but can also add other elements to the array. The function generally replaces the existing element with elements from other arrays and returns an array of removed or replaced elements.
array array_splice($array1, $start_point, $range, $array2)
Parameters: This function can take four parameters and are described below:
- $array1 (mandatory): This parameter refers to the original array, we want to operate upon.
- $start_point (mandatory): This parameter refers to the starting position of the array from where the elements need to be removed. It is mandatory to supply this value. If the value supplied is negative, then the function starts removing from the end of the array, i.e., -1 refers to the last element of the array.
- $range (optional): This parameter refers to the range or limit point up to which the removal is needed to be done. A negative value will indicate the count from the end of the string. Now, this can also be left blank. On leaving blank the function will remove all the values as mentioned in the starting point right up to the end.
- $array2 (optional): This refers to another array whose elements are to be inserted into $array1. Now for insertion of one element, we don’t need to provide the whole array. We can just pass a single string for one value. For group of values, we need an array.
Return Value: The function will return an array of the removed elements from $start_point to $range.
Below program illustrate the array_splice() function in PHP:
The returned array: Array (  => ram  => laxman  => aakash  => ravi ) The original array is modified to: Array (  => raghav  => ankita  => antara )
- How to get the function name inside a function in PHP ?
- p5.js | mag() Function
- p5.js | nfp() Function
- PHP Ds\Map sum() Function
- p5.js | nf() Function
- PHP | Ds\Set contains() Function
- PHP | Ds\Map first() Function
- PHP | pi( ) Function
- p5.js | nfc() function
- D3.js | d3.set.add() Function
- D3.js | d3.map.set() Function
- PHP | pow( ) Function
- D3.js | d3.lab() Function
- D3.js | d3.hcl() Function
- CSS | url() Function
- PHP | Ds\Set add() Function
- PHP | Ds\Set last() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.