du155305 2011-12-22 23:03
浏览 126
已采纳

如果你在php中使用shell_exec函数,是否可以获取和提取数组

I have a php script, let's call it main_script.php and if you run it through a console it returns bunch of interesting data.

I have another script, let's call it second_script.php. in second_script.php I am using shell_exec command such as

$main_script = "php main_script.php --array=true";
$output = $shell_exec($main_script);

That will, however, return output from main_script.php

What if I want main_script.php return an array. Something like this

if ($con->console_parm['array'] ){
   $whatever = array("test"=> "data son!");
   return $whatever;
}

Is there a way I can execute it through second_script.php and get that array?!

  • 写回答

1条回答 默认 最新

  • douju8782 2011-12-22 23:12
    关注

    If you print serialize($whatever); in the main script, and say $array = unserialize($output); in the second script, you'll basically end up with a copy of the main script's array.

    Just be sure that there's no extra output from the main script (i'm not sure how whitespace, for example, will affect unserialization...but it certainly can't help). And if your array has objects in it, be sure those classes are loaded (or can be autoloaded) in the other script...or you'll end up with a bunch of "incomplete class" objects that won't be useful for much.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题