Mike Atlas Mike Atlas - 5 months ago 28
PHP Question

Why can't I access the exploded array element immediately?

Why can't I immediately access elements in the array returned by


For example, this doesn't work:

$username = explode('.',$thread_user)[1];
//Parse error: syntax error, unexpected '[

But this code does:

$username = explode('.',$thread_user);
$username = $username[1];

I don't usually program in PHP, so this is rather confusing to me.


Actually, PHP simply does not support this syntax. In languages like Javascript (for instance), the parser can handle more complex nesting/chaining operations, but PHP is not one of those languages.