PHP Programing language

array_splice() Function in PHP
Previous Home Next

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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: