Re: Re: [BULK] [PHP] Use array returned by function directly?
| From: | Myron Turner | Date: | Mon, 29 Jan 2007 16:40:54 +0000 |
| Subject: | Re: Re: [BULK] [PHP] Use array returned by function directly? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247950@lists.php.net to get a copy of this message | ||
Roman Neuhauser wrote:
# turnermm02@shaw.ca / 2007-01-29 10:12:25 -0600:You can do this in Perl: my $c = (fn(@a))[2];Roman Neuhauser wrote:s/crash/syntax error/#assert(2 == returns_array()['c']);# neuhauser@sigpipe.cz / 2007-01-29 15:27:21 +0000:# crash# still crash#assert(2 == returns_array()['c']);
Not to mention C++, Python, or quite a few other languages.
But in PHP, this is a syntax error: $c = (fn($a))[2];Well, DUH! THat's what the OP was curious about: why is it an error?
Also, it's not clear what the original syntax is meant to do:Not at all! Watch this: <?php $array = 'O M F G'; $needle = ' '; assert(array('O', 'M', 'F', 'G') == explode($needle, $array)); ?> I thought the issue was this: $array = 'O M F G'; $needle = ' '; $array_2 = array('O', 'M', 'F', 'G'); assert($array == explode($needle, $array_2)); -- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/explode($needle, $array)[3] explode() takes a string and converts it to an array based on the separator expression. This might make sense:explode($needle, $array[3]) where $array[3] is a string. But explode($needle, $array), it turns out, simply returns the string "Array".