【发布时间】:2016-04-05 02:09:37
【问题描述】:
我正在使用 foreach 和 preg_match 收集一些数据,如果 preg_match 为真,它将将该元素添加到数组 $found 中,但返回此错误:
PHP 警告:array_push() 期望参数 1 为数组,字符串在 upfiles.php 第 324 行给出
$found = array();
foreach($this->disFunctions as $kkeys => $vvals)
{
if(preg_match('#'.$vvals.'#i', $cFile))
{
array_push($found, $vvals); // LINE 324
} else {
$found = '';
}
} // end foreach
print_r($found);
编辑:
将 array_push 值放入我的类中:
public final function filterFile(){
$disabled_functions = ini_get('disable_functions');
$disFunctionsNoSpace = str_replace(' ', '', $disabled_functions);
$disFunctions = explode(',', $disFunctionsNoSpace);
$this->disFunctions = $disFunctions;
// get file content of the uploaded file (renamed NOT the temporary)
$cFile = file_get_contents($this->fileDestination, FILE_USE_INCLUDE_PATH);
$found = array();
foreach($this->disFunctions as $kkeys => $vvals)
{
if(preg_match('#'.$vvals.'#i', $cFile))
{
array_push($found, $vvals);
}
} // end foreach
} // end filterFile
$up = new uploadFiles($filename);
$fileterringFile = $up->filterFile();
print_r($fileterringFile);
var_dump($fileterringFile);
感谢您一直以来的支持
【问题讨论】:
标签: php array-push