Why can't I immediately access elements in the array returned by explode()?
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.
The reason it isn't obvious how to do what you want is that explode could return false. You should check the return value before indexing into it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With