RE: [PHP] Why doesn't this work?
| From: | Jack Dempsey | Date: | Sat, 15 Sep 2001 02:56:44 +0000 |
| Subject: | RE: [PHP] Why doesn't this work? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67424@lists.php.net to get a copy of this message | ||
php doesn't have as loose a syntax as perl or python. try this:
<?
$testString = "this=is=something";
print array_shift(split("=",$testString));
?>
mind you, that only works because you wanted the 0th element, and shift
returns that first one...something else would be needed for any other
index...
jack
-----Original Message-----
From: Ray Van Dolson [mailto:rayvd@bludgeon.org]
Sent: Friday, September 14, 2001 10:14 PM
To: php-general@lists.php.net
Subject: [PHP] Why doesn't this work?
I've come across this problem enough that I want to find out if there's a
way to make it work, or if this is just a limitation of PHP. Here's what
I'm trying to do:
print split("=",$testString)[0];
This gives me a syntax error. I've also tried:
print (split("=",$testString))[0];
Along with other permutations... the only way I can get this to work how
I want it to is to create a temporary variable first.
$tempVar = split("=",$testString);
print $tempVar[0];
Now I guess this is easy enough to do, but I'm just used to doing it the
other way. And the documentation for split() says that it should return
an Array... why can't I operate on it as I would a normal array?
Anyways, thanks for any help. I guess I'm just too used to Python. :-D
Ray Van Dolson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net