PHP Programing language

adplus-dvertising
array_splice() Function in PHP
Previous Home Next
adplus-dvertising

array_splice()

The array_splice() function removes selected elements from an array and replaces it with new elements. The function also returns an array with the removed elements.

Syntax:
array_splice(array,start,length,array)

In above syntax, "array" specifies an array, "start" specifies the numeric value where the function will start removing elements, "length" specifies the numeric value how many elements will be removed, and also length of the returned array and "array" specifies an array with the elements that will be inserted to the original array.

Example:

<?php
$a1=array("a"=>"Apple","b"=>"Mango","c"=>"Banana","d"=>"Orange");
$a2=array("a"=>"Papaya","b"=>"Orange");
print_r(array_splice($a1,0,2,$a2));
?>

Output:

Array ( [a] => Apple [b] => Mango )

Previous Home Next