by @codeexamples

How to remove elements from an array in PHP

Home » php » How to remove elements from an array in PHP

Php has a built-in array_splice() function by using that we can remove elements from an array.

Here is an example that removes the second and third elements from an array.

<?php
$fruits=array("apples","bananas","grapes","cherries");

// removing starts from index 1 and remove 2 elements including index 1
array_splice($fruits,1,2);

print_r($fruits);

?>

Output:

Array ( [0] => apples [1] => cherries )