I have few php functions that returns various data via same variable, and that variable should assign to a array. Now I want to execute function by checking $_POST and assign $data to $response multidimensional array… Is there any way to do that ???
$functionname = $_POST['functionname'];
function testOne(){
$data = array('test'=>'value1');
return $data;
}
function testTwo(){
$data = array('test'=>'value2');
return $data;
}
//Here I need to execte each functions and return $data
$response = array('result' => array('response'=>'success'),'clients' => $data);
print_r($response);
Functions are only run when they’re called. You haven’t called either of your functions.
From the looks of your code, I assume that
$functionnamewill take a value of eithertestOneortestTwo, which then tells the code what function to run. What you want to do, then, is call the function using the variable function name and capture the returned value into a variable:See the docs for, well… the docs.