Inline Selection of array element on function return?
Posted: Tue Aug 16, 2011 3:24 pm
Hi folks,
I'm wondering if there is a way to reference a single element of an array which a function returns.
Lets say I have a function named test_function() it takes no arguments and returns an array. Lets also say that I have no control over the output of the function.
In order to dump a specific element of that array I would do this:
$temp = test_function();
var_dump($temp[3]);
I'm looking to replace those two lines with something like this...
var_dump(test_function()[3]);
Yet that approach doesn't work.
Any suggestions?
I'm wondering if there is a way to reference a single element of an array which a function returns.
Lets say I have a function named test_function() it takes no arguments and returns an array. Lets also say that I have no control over the output of the function.
In order to dump a specific element of that array I would do this:
$temp = test_function();
var_dump($temp[3]);
I'm looking to replace those two lines with something like this...
var_dump(test_function()[3]);
Yet that approach doesn't work.
Any suggestions?