In Javascript, after executing a function I can immediately get the an element of the array returned by the function, like so:

myFunc("birds")[0] //gets element zero returned from "myFunc()"

This is much easier and faster than doing this:

$myArray = myFunc("birds");
echo $myArray[0];

Does PHP have a similar shorthand to javascript? I'm just curious. Thanks in advance!

Accepted Answer

No, unfortunately in PHP you can only subscript an array variable, no other kind of array returning expression.

Written by Matteo Riva
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki