Possible Duplicate:
Interpreting return value of function directly as an array
Is there any way to access an element of the resulting array directly after calling explode() function in PHP?
e.g.:
echo explode('-', 'a-b-c')[1];
would return b
Possible Duplicate:
Interpreting return value of function directly as an array
Is there any way to access an element of the resulting array directly after calling explode() function in PHP?
e.g.:
echo explode('-', 'a-b-c')[1];
would return b
There currently is no support for this in PHP. I believe PHP 5.4 (which is in BETA testing right now) is going to support this though.
for now you would just have to break it in two lines:
$arr = explode('-', 'a-b-c');
$arr[1]
This is currently not possible with the stable release of PHP (5.3), but will be included in PHP 5.4. The feature is already marked as "implemented" in the rfc list of the php wiki.