0

Why does this work:

$parts = explode('#', $url);
$url = $parts[0];

while this doesn't:

$url = explode('#', $url)[0];

?

davidhq
  • 4,516
  • 5
  • 29
  • 40

1 Answers1

8

Direct de-referencing of an array, like in your second code example, was added to PHP 5.4. Before 5.4, it was a syntax error.

<= 5.3

    $foo = array(....);
    echo $foo[1];

>= 5.4

    echo array(...)[1];
Marc B
  • 348,685
  • 41
  • 398
  • 480
  • 1
    was going to post the same; please add: http://www.php.net/manual/en/migration54.new-features.php – Luceos Jan 14 '14 at 15:37