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?!
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.