by Sai gowtham

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 )

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course