0

Is there a way to act directly on an array value returned from a function without assigning it to another variable first?

For example, if I just want the third value in a CSV record, I might like to do it like this:

$value = preg_split('/,/', "one,two,three,four")[2];

But that doesn't work. I've also tried with parentheses and/or curly braces in different positions around the preg_split().

Thank you.

--
Ghodmode

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by somedude3488
1

I use list and explode.

list( ,,$value ) = explode( ',','one,two,three,four' );
echo $value; //returns three
Votes + Comments
exactly what I was looking for
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.