Re: Referencing the return value of split()

From: Date: Sat, 11 Aug 2001 00:39:25 +0000
Subject: Re: Referencing the return value of split()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62234@lists.php.net to get a copy of this message
You wrote: > Hello, > > I'm trying to use the following in a piece of code, but I keep > receiving parse errors: > > $myVar = split(":", $myStrings)[0]; > > The following code works, however: > > $myTempVar = split(":", $myStrings); > $myVar = $myTempVar[0]; > > I'd much rather execute the statement in one line, rather than two, > if possible. The PHP Manual states that split() returns an array. Why > can I not reference the returned array immediately? It works in Perl... =) > Thanks for any help! > > -David Fuchs Because Perl is better than PHP! :D What you could do is: list($myVar) = split(":", $myStrings); Not tested, but it should work. HTH! :D If you want to do it Perl style, you could do this, forcing list context: $myVar = (split(":", $myStrings))[0]; But I really doubt that will work, because PHP isn't Perl. ;) -- -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/

« previous php.general (#62234) next »