HOME | PHP Tutorial | CSS
facebook icon
PHP Tutorial

PHP forms
HTML Tutorial

CSS Tutorial

PHP delete an element from an array

Next Page >>
PHP eregi_replace()

If you want to delete just one array element you can use \unset() or alternative \array_splice(). How can you remove an element from an array when you know the elements name? for example:

Example: delete plums
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');

how to solve it?
Use array_search to get the key and remove it with unset if found:

Example: delete plums

$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
if (($key = array_search('plums', $array)) !== false) {
echo $key;

If there can be multiple items with the same value, you can use array_keys to get the keys to all items:

Example: delete plums
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
foreach (array_keys($array, 'plums') as $key) {
echo $key;

Next Page >>
PHP eregi_replace()

php delete an element PHP delete an element from an array - php tutorial

3220. PHP Install, php tutorial
PHP Install php tutorial

3216. PHP 5 Constants, php tutorial
PHP 5 Constants php tutorial

2603. PHP Tutorial - Learn PHP in simple and easy steps starting from basic to advanced, php tutorial
PHP Tutorial - Learn PHP in simple and easy steps starting from basic to advanced php tutorial

43. PHP Tutorial - An Ultimate Guide for Beginners
PHP Tutorials for Beginners - Learn how to create a dynamic and interactive website using the PHP 7 programming language in simple and easy steps.

3352. PHP Database Driven Website
Use PHP to create a database driven website with this PHP tutorial.

3359. PHP Installation
Learn to install PHP with this PHP tutorial.

Your add here
PHP empty() Function

PHP strtolower() function

PHP ltrim() function

PHP implode() function

PHP str_split() function

PHP similar_text() function

PHP ucwords() function

PHP strstr() function

PHP strrchr() Function

PHP str_repeat() function

PHP rtrim() function

PHP printf() function

PHP strip_tags() function

PHP print() function

PHP substr() function

PHP html_entity_decode() function

Function eregi_replace() is deprecated in php - How to fix
CSS width and height - CSS Properties - Dimensions units
CSS Text Style - Text Font Size - Text Align
HTML div class tag attribute
How to create HTML link without underline
HTML Font Face