Php Array Elements Splice Function

What is array_splice Function?


The "array_splice" function is used remove a portion of the array and replace it with something else.



In the above syntax "array" specifies the array from which the elements need to be removed, "start" specifies from where the function will start removing elements, if a negative number is given, it will start from the end of the array, "length" specifies the number of elements to be removed,"array" is an optional field for an array to be inserted.

Example :

$b=array("c"=>"Cherry","b"=>"Strawberry", "a"=>"Cherry");
$a=array("d"=>"Orange", "e"=>"Guava");
Result :

Array ( [d]= Orange [e]= Guava [a]=> Cherry );

In the above example the first 2 elements of the array "$b" are removed and replaced with elements in array "$a".

PHP Topics

Ask Questions

Ask Question