- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to delete an element from the array using the unset function
To delete an element from the array using the unset function, the PHP code is as follows −
Example
<?php $my_array = array("Joe", "Ben", "Mary", "Barun", "Sona", "Mona"); unset($my_array[4]); print_r("After deleting the element, the array is"); print_r ($my_array); ?>
Output
After deleting the element, the array isArray ( [0] => Joe [1] => Ben [2] => Mary [3] => Barun [5] => Mona )
Above, an array is defined, with multiple strings −
$my_array = array("Joe", "Ben", "Mary", "Barun", "Sona", "Mona");
The unset function is used, by specifying the index of the element in the array that needs to be deleted. After the element is deleted, the output/array is printed on the screen −
unset($my_array[4]); print_r("After deleting the element, the array is"); print_r ($my_array);
- Related Articles
- How to delete an element from an array in PHP and re-index the array?
- C program to delete an array element using Pointers
- Unset an attribute from a single array element in MongoDB?
- Delete an element from array using two traversals and one traversal in C++ program
- Program to get the last element from an array using C#
- How to delete an array element based on key in PHP?
- PHP program to find the minimum element in an array
- PHP program to find the maximum element in an array
- How to delete element from an array in MongoDB?
- How to delete/remove an element from a C# array?
- C# Program to find the smallest element from an array using Lambda Expressions
- C# Program to find the largest element from an array using Lambda Expressions
- Delete an element from array using two traversals and one traversal in C++?
- C# program to get the last element from an array
- C# Program to find the smallest element from an array

Advertisements