I have an array that looks like this:
Array ( [0] => Vice President [1] => [2] => other [3] => Treasurer )
and I want delete the value with other
in the value.
I tried to use array_filter()
to filter this word, but array_filter()
will delete all the empty values too.
I want the result to be like this:
Array ( [0] => Vice President [1] => [2] => Treasurer )
This is my PHP filter code:
function filter($element) {
$bad_words = array('other');
list($name, $extension) = explode(".", $element);
if (in_array($name, $bad_words))
return;
return $element;
}
$sport_level_new_arr = array_filter($sport_level_name_arr, "filter");
$sport_level_new_arr = array_values($sport_level_new_arr);
$sport_level_name = serialize($sport_level_new_arr);
Can I use another method to filter this word?
array_filter()
's callback, you don't retun the value, you returntrue
orfalse
. When you return the empty string as$element
,array_filter()
interprets that falsey value to mean that that element should be destroyed. – Tardiff