Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php access array value from function return

Tags:

arrays

scope

php

silly php question... why cant i do this?

echo Auth::getFullUser()[ 'country' ];

instead you have to do this

$user = Auth::getFullUser();
echo $user[ 'country' ];
like image 511
David Morrow Avatar asked May 20 '10 15:05

David Morrow


People also ask

How is it possible to return a value from a function in PHP?

A function can return a value using the return statement in conjunction with a value or object. return stops the execution of the function and sends the value back to the calling code. You can return more than one value from a function using return array(1,2,3,4).

Which function returns the number of elements in an array PHP?

The count() function returns the number of elements in an array.


1 Answers

The syntax just doesn't allow it unfortunately.

AFAIK there was at one time intention to put that syntax in PHP6, but it has been dropped.

like image 154
Amy B Avatar answered Nov 02 '22 19:11

Amy B