note 93103 deleted from function.array-search by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:17:42 +0000 |
| Subject: | note 93103 deleted from function.array-search by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213746@lists.php.net to get a copy of this message | ||
Note Submitter: Nguyen KimKha
----
You can remove some values from array, by using unset() and array_search().
<?php
$friends = array( 'Bob', 'Ann', 'Peter' ); // Two persons named
'Bob'
$find = 'Bob';
$key = array_search( $find, $friends ); // Find key of given value
if ($key != NULL || $key !== FALSE) {
unset($friends[$key]); // remove key from array
}
// Now, $friends = array( 'Ann', 'Peter');
?>