Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 分解和数组内搜索不工作_Php - Fatal编程技术网

Php 分解和数组内搜索不工作

Php 分解和数组内搜索不工作,php,Php,好的,这是代码板 好的,这是我的函数,它应该通过过滤$omit变量返回单词数组。但是当我使用它时,第一个$omit数组中的单词只被过滤,第二个从$exclude\u列表中合并的单词不被过滤 我是这样使用我的函数的: $filter_array = explode("\n", words list separated by \n new line here); print_r(processContent('String gere for filtering', $min_word_length,

好的,这是代码板

好的,这是我的函数,它应该通过过滤
$omit
变量返回单词数组。但是当我使用它时,第一个
$omit
数组中的单词只被过滤,第二个从
$exclude\u列表中合并的单词不被过滤

我是这样使用我的函数的:

$filter_array = explode("\n", words list separated by \n new line here);
print_r(processContent('String gere for filtering', $min_word_length, $filter_array));

变量
$filter\u数组
被传递到exclude\u列表,也被合并以忽略变量,但不会在返回值中过滤。仅过滤第一个
$omit
值。代码中是否有错误???

问题在于
$filter\u数组中有空格。要么:

$filter_array = array_map(function($el) { return trim($el); }, $filter_array);

您需要将其通过修剪:

$filter_array = array_map(function($el) { return trim($el); }, $filter_array);

看看这个代码板。同样的错误你的代码板示例应该是array('of','for'),而不是array('of',for'),这是第一个。它在代码板中工作,但在我的服务器上不工作。你在服务器上得到了什么?
foreach ($filter_array as &$element) {
    $element = trim($element);
}
$filter_array = array_map(function($el) { return trim($el); }, $filter_array);