note 100813 modified in function.array-filter by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Nov 2010 19:15:33 +0000 |
| Subject: | note 100813 modified in function.array-filter by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173866@lists.php.net to get a copy of this message | ||
Here is how you could easily delete a specific value from an array with array_filter:
<?php
$array = array (1, 3, 3, 5, 6);
$my_value = 3;
$filtered_array = array_filter($array, function ($element) use ($my_value) { return ($element !=
$my_value); } );
print_r($filtered_array);
?>
output:
Array
(
[0] => 1
[3] => 5
[4] => 6
)
--was--
Here is how you could easily delete a specific value from an array with array_filter:
$array = array (1, 3, 3, 5, 6);
$my_value = 3;
$filtered_array = array_filter($array, function ($element) use ($my_value) { return ($element !=
$my_value); } );
print_r($filtered_array);
output:
Array
(
[0] => 1
[3] => 5
[4] => 6
)
http://php.net/manual/en/function.array-filter.php