If I have a function like so:
function foo(){
return array("hello" => "world");
}
I can’t call the function and operate on the return value like so
$test = foo()["hello"];
Instead I have to break it up across two lines like so
$test = foo();
$test = $test["hello"];
Is there any way around this? If not, why does PHP enforce this. Also, if it’s of any consequence, foo() actually returns a two dimensional array.
PHP does not have array deferencing, the functionality you are asking for.
PHP 5.4, the upcoming version of PHP, does have this feature.