-2

For example:

<?php
    $text="/p hello";
    $a= explode("/",$text);
    $a=$a[1];
    echo $a;
?>

works, however:

<?php
    $text="/p hello";
    $a= explode("/",$text)[1];
    echo $a;
?>

results in a syntax error. In python you can just treat a recall to a function that returns a list/array as a list/array. Is this the same for php?

skirato
  • 763
  • 6
  • 26
ryanolee
  • 89
  • 4

1 Answers1

4

In PHP version >= 5.4.0 it will not result in error, but will echo p_hello. You can check it here, changing the version number:

http://sandbox.onlinephpfunctions.com/code/db319c296ea4eb9500b9fa16bccd8f927c733d14

It is called Function Array Dereferencing:

https://wiki.php.net/rfc/functionarraydereferencing

n-dru
  • 9,285
  • 2
  • 29
  • 42