Possible Duplicate:
PHP syntax for dereferencing function result
If a PHP function returns an array, the following syntax will not work:
$firstValue = $object->methodThatReturnsArray()[0]; // syntax error, unexpected '['
This, however, works fine:
$temporaryArray = $object->methodThatReturnsArray();
$firstValue = $temporaryArray[0]; // temporary will never be reused
What is the best syntax to solve this problem, or is creating that variable the recommended approach?
Variable is the best approach.
Still PHP 5.4 adds the feature to be able using the first mentioned syntax.