Why can’t I get array key value after function?

I’m calling this WordPress function:

get_user_meta($user->ID, "user_address");

And it returns array, I don’t want to put this into variable but simply echo it out.

Read More

But this doesn’t work:

get_user_meta($user->ID, "user_address")[0];

Why? any way to do this as one liner?

Related posts

Leave a Reply

3 comments

  1. Dereferencing an array immediately when it is returned by a function is a relatively new feature in PHP 5.4. You are most likely using 5.3 or older, in which case you cannot immediately access an element of an array returned by a function call.

    As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.

    http://docs.php.net/manual/en/language.types.array.php