0

i have this issue echoing arrays in php.

In my localhost i can echo an array value like this:

echo explode(",", $emails)[1];

In server i receive this message.

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home

But on the server doesn't work, does anyone know why? i think because the PHP version, so, if because this do you know how to enable the echo this way?

Thanks.

Aztrozero
  • 133
  • 1
  • 8
  • what's the output of `print_r($emails);` ? – Jeff Puckett Mar 26 '16 at 02:59
  • Why duplicate? i'am asking about echoing the explode function with php. Please press ctrl+f and try to find "explode" in the asnwer you say it's duplicated, you dont find anything related to explode. – Aztrozero Mar 26 '16 at 03:11
  • 1
    It is a version difference. I'm guessing you're running PHP 5.3 or older on the server. – Matt Mar 26 '16 at 03:18
  • 1
    The line giving you the error involves array dereferencing, the ability to get an array key value from the return value of an expression (like "explode"). Your local version of PHP is modern enough to include it (5.4 or newer) but your server version is not. The workaround is easy enough - use a temporary variable. `$emails_array = explode(",", $emails); echo $emails_array[1];` – David White Mar 26 '16 at 03:44
  • Thank you guys, you both have the right answer i think i need move to another server with a modern PHP version. – Aztrozero Mar 26 '16 at 03:47

0 Answers0