I want to modify the array in the first function using the second function but it doesn't return the result where it should(first Function).
function first(){
$results = [
'programs' => [],
'events' => [],
];
second('program', $results);
print_r($results); // Don't get results here
}
function second($type,$arr){
$type .= 's';
if(array_key_exists($type,$arr)){
array_push($arr[$type],'title');
}
print_r($arr); // Get results here
}
first();
second, you need to declare the parameter as a ref parameter using&$arr$results = second('program', $results);andfunction second($type, $arr){ ... return $arr; }or pass the array by-reference usingfunction second($type, &$arr).