0

Why does this work:

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

while this doesn't:

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

?

davidhq
  • 4,660
  • 6
  • 30
  • 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
  • 356,200
  • 43
  • 426
  • 500
  • 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