|
|
Php Array Elements Splice Function
|
Tutorials » Php »
|
Topic |
What is array_splice Function?
|
|
Explanation |
|
The "array_splice" function is used remove a portion of the array and replace it with something else.
Syntax:
array_splice(array,start,length,array)
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:
<?php
$b=array("c"=>"Cherry","b"=>"Strawberry", "a"=>"Cherry");
$a=array("d"=>"Orange", "e"=>"Guava");
array_splice($b,0,2,$a);
print_r($b);
?>
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".
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|