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!
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.
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.
No, unfortunately in PHP you can only subscript an array variable, no other kind of array returning expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With