警告:in_array()预计参数2为array [英] Warning: in_array() expects parameter 2 to be array
本文介绍了警告:in_array()预计参数2为array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读了PHP in_array 手册,并创建一些$ C $ ç线。
I read the php in_array manual and create some code lines.
$handle = fopen("/path/to/file", "a") or die('Cannot open file:');
$y= $command_name1.$steps1;
$x=trim(shell_exec("grep -ri -o '$y' /path/to/file "));
$Z=array($x);
if (in_array($y,$z,false))
{
echo "thise 2 variables are already in this file";
fclose($handle);
}
else {
//write some thing on that file
}
不过,这给上述错误。我想知道的是,可2个变量( $ command_name1
和 $ steps1
)相加,并通过<搜吧code> in_array ?
推荐答案
$ X
不是数组,所以你得到这个错误。
$x
isn't an array, so you get that error.
看看以 in_array( )
定义和使用。
你可以从函数签名见
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
您需要第二个参数(在这种情况下 $大海捞针
)是一个数组,而不是一个标值(这是任何类型)
you need second argument (in that case $haystack
) to be an array and not a scalar value (whatever type it is)
这篇关于警告:in_array()预计参数2为array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文