删除包含php中某些字符的数组中的单词[duplicate]

This question already has an answer here:

I have an array:-

array("abc", "cba", "bbc", "dde", "acf");

I want to remove word which contains "a" character.

Output Should be:

array ("bbc", "dde");

How it is done in PHP ?

</div>

try this :

<?php
    $myArray = array("abc", "bcd", "hgd", "hav");

    foreach($myArray as $key => $value) {
        if(strpos($myArray[$key], "a") !== false) {
            unset($myArray[$key]);
        }
    }

    die(var_dump($myArray));
?>

Result :

array(2) { [1]=> string(3) "bcd" [2]=> string(3) "hgd" }

However, you can simply use this :

function myFilter($string) {
  return strpos($string, '?') === false;
}

$newArray = array_filter($array, 'myFilter');

You need array_filter:

$array = ['asd','fdd', 'bbb', 'bba'];
$filter = 'a';
$array = array_filter($array, function($a) use ($filter) {
    return strpos($a, $filter) === false;
});