For the life of me, I can't understand this godforsaken language. This:
$x = explode(' ', 'a b c');
echo $x[0];
works just fine. But:
echo explode(' ', 'a b c')[0];
returns an error. What gives?
That syntax isn't supported by the PHP parser, yet. It is called array dereferencing and has been added in the PHP trunk already.
You can do that in PHP 5.4... it's time to upgrade.
Per the manual:
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.
As of PHP 5.5 it is possible to array dereference an array literal.
<?php
function getArray() {
return array(1, 2, 3);
}
// on PHP 5.4
$secondElement = getArray()[1];
// previously
$tmp = getArray();
$secondElement = $tmp[1];
// or
list(, $secondElement) = getArray();
?>
echo current(explode(' ', 'a b c'));