Write a PHP script to delete a specific value from an array using array_filter() function
<?php $colors = array('key1' => 'Red', 'key2' => 'Green', 'key3' => 'Black'); $given_value = 'Black'; print_r($colors); $new_filtered_array = array_filter($colors, function ($element) use ($given_value) { return ($element != $given_value);}); print_r($filtered_array); print_r($new_filtered_array); ?>
Sample Output:
Array ( [key1] => Red [key2] => Green [key3] => Black ) PHP Notice: Undefined variable: filtered_array in /home/stu dents/2f6e9db0-f423-11e6-a8c0-b738b9ff32f9.php on line 7 Array ( [key1] => Red [key2] => Green )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
Array ( [key1] => Red [key2] => Green [key3] => Black ) PHP Notice: Undefined variable: filtered_array in /home/stu dents/2f6e9db0-f423-11e6-a8c0-b738b9ff32f9.php on line 7 Array ( [key1] => Red [key2] => Green )need an explanation for this answer? contact us directly to get an explanation for this answer