[英]in_array() expects parameter 2 to be array, null given in
I'm trying to run a command that outputs when the results whenever something changes.我正在尝试运行一个命令,该命令在结果发生变化时输出。 However, I keep getting an in_array() expects parameter 2 to be array, resource given in
error.但是,我不断收到in_array() expects parameter 2 to be array, resource given in
错误in_array() expects parameter 2 to be array, resource given in
。
Here is my code:这是我的代码:
$call = "~/www/reteps.tk/go/kahoot-auto " . '262671' . " " . 'bob' . " ";
$result = array();
$old_result = array(0 => "something");
$handle = popen($call, "r");
$result = file($handle); #is this how I read the results?
while (in_array("end",$result) != true) {
sleep(1);
if ($result != $old_result) {
echo($result);
$old_result = $result;
}
}
Full Error log:完整的错误日志:
PHP Warning: file() expects parameter 1 to be a valid path, resource given in /home/retep/www/reteps.tk/school/kahoot2.php on line 70
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
您必须将文件的路径(可能是$call
)放在file
函数中,然后放置一个资源( $result
)
Can you provide the value of $call?你能提供 $call 的价值吗? The error seems to indicate that it's a resource instead of a path.该错误似乎表明它是资源而不是路径。 popen() requires a $command: popen() 需要一个 $command:
http://php.net/manual/en/function.popen.php http://php.net/manual/en/function.popen.php
So $call should be a string of some kind, either a Linux command or executable file path or something.所以 $call 应该是某种字符串,可以是 Linux 命令或可执行文件路径或其他东西。 Right now $call appears to be a resource, so the path or command may be INSIDE of the resource and you just need to point to that value instead of the resource itself.现在 $call 似乎是一个资源,所以路径或命令可能在资源的内部,你只需要指向那个值而不是资源本身。
//my code //我的代码
$r=array(10.5,11,45,78,85,90);
if(in_array(4,$r)) {
echo "number is found";
} else {
echo "number is not found";
}
Your path specified for file is not found by the system.系统找不到您为文件指定的路径。 Hence, $result doesn't gets any value.因此, $result 没有任何价值。 And in your next statement in array requires 2nd parameter to be array, but $result is not an array as path was not valid.在数组中的下一个语句中,需要第二个参数为数组,但 $result 不是数组,因为路径无效。
Your in array code is fine.您的数组代码很好。 Just check the path of the file.只需检查文件的路径。 It will solve your problem.它会解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.