Access array returned by a function in php

Since PHP 5.4 it’s possible to do exactly that:

getSomeArray()[2]

Reference: https://secure.php.net/manual/en/language.types.array.php#example-62

On PHP 5.3 or earlier, you’ll need to use a temporary variable.

Leave a Comment