PHP array_splice() Function

PHP array_splice() Function

The array_splice() function in PHP is used to remove a portion of the array and replaces them with the elements of the replacement array.

Syntax

Parameter

input(required)– This array represents the input array.

offset(required)-This parameter signifies the starting position of the array from where the splicing needs to be performed. The various offset values are as follows:

  • If it is greater than 0, the start of the removed portion is at that offset from the beginning of the input array.
  • If offset is negative, the start of the removed portion is at that offset from the end of the input array.

length(optional)– This parameter refers to the range or limit point upto which the splicing is needed to be done.

  • If length is not specified, it removes everything from offset to the end of the array.
  • If length is positive, the specified number of elements will be removed.
  • If length is negative, the end of the removed portion will be that many elements from the end of the array.
  • If length is equal to zero, no elements will be removed.

replacement (optional)– This parameter represents the replacement array wherein the removed elements are replaced with elements from this array.

Return

This function returns an array consisting of the extracted elements.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output