|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-31 05:59 UTC] jrhodes at roket-enterprises dot com
[2009-12-31 06:24 UTC] joey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 14:00:01 2025 UTC |
Description: ------------ In Perl, I am able to do something like: print (explode(",", $myString))[1]; which would print the second result of explode (which returns an array). Sadly, this feature is lacking in PHP. I'd really like to see this in PHP, because it adds so much convenience to coding, and shortens it, rather than having to assign to a variable, then obtaining the value from the variable. Reproduce code: --------------- <?php $myString = "The,quick,brown,fox"; $secondpart = (explode(",", $myString))[1]; echo $secondpart; ?> Expected result: ---------------- quick Actual result: -------------- Parse error: syntax error, unexpected '[' in /home/billy/Desktop/index.php on line 3