Why does this code fail
function f(){
return array('k'=>'abc');
}
print_r(f()['k']);
and this code work?
function f(){
return array('k'=>'abc');
}
$a = f();
print_r($a['k']);
The only difference is the assignment of f
's result to $a
before trying to access elements of the array. How can I reference the result of f
directly without the additional assignment?