act directly on an array value returned by a function?

Thread Solved

Join Date: Sep 2009
Posts: 11
Reputation: Ghodmode is an unknown quantity at this point 
Solved Threads: 3
Ghodmode's Avatar
Ghodmode Ghodmode is offline Offline
Newbie Poster

act directly on an array value returned by a function?

 
0
  #1
Oct 3rd, 2009
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:
  1. $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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: act directly on an array value returned by a function?

 
1
  #2
Oct 3rd, 2009
I use list and explode.
  1. list( ,,$value ) = explode( ',','one,two,three,four' );
  2. echo $value; //returns three
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC