Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Array access short-hand?

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!

like image 412
mattsven Avatar asked Mar 20 '10 23:03

mattsven


People also ask

What is Array_keys () used for in PHP?

The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys. Parameters: The function takes three parameters out of which one is mandatory and other two are optional.

What is indexed array in PHP?

PHP indexed array is an array which is represented by an index number by default. All elements of array are represented by an index number which starts from 0. PHP indexed array can store numbers, strings or any object. PHP indexed array is also known as numeric array.


1 Answers

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

like image 55
Matteo Riva Avatar answered Sep 20 '22 02:09

Matteo Riva