Home Ask Login Register

Developers Planet

Your answer is one click away!

user5898266 February 2016

calling a php function with exec()

I am trying to use exec() to run and pass parameters to a php function named new_array() in array_module.php and expect an array return but having no luck. using the format:

$cmd = exec('cd "c:/wamp/www/test_array" && php array_module.php "'.$input['first'].'" 
     "'.$input['second'].'" ');

Any help is appreciated


deceze February 2016

Don't make a call through the command line to another file. Import the other file so its functions become available and simply call the function directly:

require_once 'c:/wamp/www/test_array/array_module.php';

$result = new_array($input['first'], $input['second']);

This assumes that array_module.php is written in a sane way so it can be imported elsewhere of course, e.g.:


function new_array($one, $two) {
    return $result;

Post Status

Asked in February 2016
Viewed 2,126 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life