PHP delete an element from an array
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
<?php
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
?>
$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
<?php
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
if (($key = array_search('plums', $array)) !== false) {
unset($array[$key]);
}
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
<?php
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
foreach (array_keys($array, 'plums') as $key) {
unset($array[$key]);
}
echo $key;
?>
$array = array('pears', 'apple', 'orange', 'strawberry', 'plums', 'kiwi');
foreach (array_keys($array, 'plums') as $key) {
unset($array[$key]);
}
echo $key;
?>
php delete an element
PHP delete an element from an array - php tutorial
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.