944,001 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 613
  • PHP RSS
Oct 3rd, 2009
0

act directly on an array value returned by a function?

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Ghodmode is offline Offline
11 posts
since Sep 2009
Oct 3rd, 2009
1

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

I use list and explode.
PHP Syntax (Toggle Plain Text)
  1. list( ,,$value ) = explode( ',','one,two,three,four' );
  2. echo $value; //returns three
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Formated Source Code
Next Thread in PHP Forum Timeline: hyperlink to last page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC