[英]php using exec output as array and iterate over
I am stuck on this.. I am a perl programmer and trying to use php has gotten me stuck on this one issue. 我被困在这..我是一个perl程序员,尝试使用php使我陷入了这个问题。 I want to run a system command(or whatever script I have) and use the output as array and loop it through.
我想运行系统命令(或我拥有的任何脚本),并将输出用作数组并循环通过。
For an example 举个例子
exec("/bin/myScript.pl $criteria1", $outputArray);
foreach ($item as $outputArray) {
print $item . "<br />";
}
I am not sure why above do not work. 我不确定为什么上述方法不起作用。 When I do print_r($outputArray), I see the results, but I want to iterate through them and do whatever I need to do.
当我执行print_r($ outputArray)时,我看到了结果,但是我想遍历它们并做我需要做的任何事情。 What am I missing?
我想念什么? OR am I looking at this from NONE php perspective?
还是我从无PHP的角度来看这个?
Please help 请帮忙
You are using foreach
in the wrong way: 您使用错误的方式使用了
foreach
:
exec("/bin/myScript.pl $criteria1", $outputArray);
foreach ($outputArray as $item) { // <------
print $item . "<br />";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.