I'd like to access a single element from a function that returns an
array; and I'd like to do it in a single statement.
Here's an example. This is obvious.
$a = explode(".", "this.is.some.t ext");
$b = $a[2];
So how can I do that in a single statement?
$a = explode(".", "this.is.some.t ext")[2] // no
$a = (explode(".", "this.is.some.t ext"))[2] // nope
$a = [explode(".", "this.is.some.t ext")][2] // no way
How close am I coming to the final result. My goal is to be able to
nest them.
I was looking for an answer in the array functions, but the ones I
found don't return a scalar value, they return arrays in my cases.
Thanks,
M. Katz
array; and I'd like to do it in a single statement.
Here's an example. This is obvious.
$a = explode(".", "this.is.some.t ext");
$b = $a[2];
So how can I do that in a single statement?
$a = explode(".", "this.is.some.t ext")[2] // no
$a = (explode(".", "this.is.some.t ext"))[2] // nope
$a = [explode(".", "this.is.some.t ext")][2] // no way
How close am I coming to the final result. My goal is to be able to
nest them.
I was looking for an answer in the array functions, but the ones I
found don't return a scalar value, they return arrays in my cases.
Thanks,
M. Katz
Comment