PHP | Program to delete an element from array using unset() function Last Updated : 27 Apr, 2018 Comments Improve Suggest changes Like Article Like Report Given an array of elements, we have to delete an element from the array by using the unset() function. Examples: Input : $arr = array("Harsh", "Nishant", "Bikash", "Barun"); unset($arr[3]); Output : Array ( [0] => Harsh [1] => Nishant [2] => Bikash ) Input : $arr = array(1, 2, 6, 7, 8, 9); unset($arr[3]); Output : Array ( [0] => 1 [1] => 2 [2] => 6 [4] => 8 [5] => 9 ) unset() function: The function accepts a variable name as parameter and destroy or unset that variable. Approach: This idea to solve this problem using the unset function is to pass the array key of the respective element which we want to delete from the array as a parameter to this function and thus removes the value associated to it i.e. the element of an array at that index. Below programs illustrate the above approach: Program 1: php <?php $a = array("Harsh", "Bikash", "Nishant", "Barun", "Deep"); // unset command accepts 3rd index and // thus removes the array element at // that position unset($a[3]); print_r ($a); ?> Output: Array ( [0] => Harsh [1] => Bikash [2] => Nishant [4] => Deep ) Program 2: php <?php $a = array(1, 8, 9, 7, 3, 5, 4, ); // unset command accepts 3rd index and // thus removes the array element // at that position unset($a[5]); print_r ($a); ?> Output: Array ( [0] => 1 [1] => 8 [2] => 9 [3] => 7 [4] => 3 [6] => 4 ) Note: The array keys will not be reordered after using the unset() function. Comment More infoAdvertise with us Next Article PHP | Program to delete an element from array using unset() function A akash1295 Follow Improve Article Tags : Technical Scripter Web Technologies PHP Similar Reads How to delete an Element From an Array in PHP ? To delete an element from an array means to remove a specific value or item from the array, shifting subsequent elements to the left to fill the gap. This operation adjusts the array's length accordingly, eliminating the specified element.This article discusses some of the most common methods used i 4 min read How to delete an element from an array using JavaScript ? The array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index. In this article, we will discuss different ways to remove elements from the array. 5 min read PHP | Deleting an element from array using array_diff() Given an array, we have to delete an element from that array using the array_diff() function in PHP.Examples:Input : $arr = array(2, 8, 9, 7, 6, 5); $arr = array_diff($arr, array(9)); Output : Array ( [0] => 2 [1] => 8 [3] => 7 [4] => 6 [5] => 5 ) Input : $arr = array("shubham", "aksh 2 min read Remove First Element from an Array in PHP Given an array, the task is to remove the first element from an array in PHP. Examples:Input: arr = [1, 2, 3, 4, 5, 6, 7]; Output: 2, 3, 4, 5, 6, 7 Input: arr = [3, 4, 5, 6, 7, 1, 2] Output: 4, 5, 6, 7, 1, 2Below are the methods to remove the first element from an array in PHP:Table of ContentUsing 3 min read PHP | Remove duplicate elements from Array You are given an Array of n-elements.You have to remove the duplicate values without using any loop in PHP and print the array. Examples: Input : array[] = {2, 3, 1, 6, 1, 6, 2, 3} Output : array ( [6] => 2 [7] => 3 [4] => 1 [5] => 6 ) Input : array[] = {4, 2, 7, 3, 2, 7, 3} Output : arr 3 min read Removing Array Element and Re-Indexing in PHP In order to remove an element from an array, we can use unset() function which removes the element from an array, and then use array_values() function which indexes the array numerically automatically. Function Usedunset(): This function unsets a given variable. Syntax:void unset ( mixed $var [, mix 2 min read How to remove specific elements from the left of a given array of elements using JavaScript ? In this article, we will learn How to remove specific elements from the left of a given array of elements using JavaScript. We have given an array of elements, and we have to remove specific elements from the left of a given array. Here are some common approaches: Table of Content Using splice() met 2 min read Different Ways to Remove an Element From Set in C++ STL Prerequisite: Set in C++ There are multiple ways to remove an element from the set. These are as follows: Removing an element by its valueRemoving an element by its indexRemoving an element by an iterator Example: Input set s={10, 20, 30, 40, 50} , value=40 // Removing 40 from the set Output set s={ 3 min read How to remove duplicate values from array using PHP? In this article, we will discuss removing duplicate elements from an array in PHP. We can get the unique elements by using array_unique() function. This function will remove the duplicate values from the array.Syntax:array array_unique($array, $sort_flags);Note: The keys of the array are preserved i 4 min read JavaScript - How to Remove an Element from an Array? Removing elements from an array is a fundamental operation in JavaScript, essential for data manipulation, filtering, and transformation. This guide will explore different methods to efficiently remove elements from an array, enhancing your understanding and capability in handling arrays.1. Using po 3 min read Like