0

Given the line of code, $result = pg_fetch_all(pg_query($dbconn, $query))[0];

locally, on my MacBook, it runs just fine. On Heroku, this is also the case. On Amazon EC2, however (using Amazon Linux, not that that makes a difference), this line shows up in my logfile and it doesn't allow it: PHP Parse error: syntax error, unexpected '[' in /var/www/html/index.php on line ...

Reading the docs, pg_fetch_all returns a 0-based indexed array of associative arrays. So my question is, why can I not use pg_fetch_all(whatever)[0] or is it just a weird quirk of Amazon's system?

Tyler Sebastian
  • 9,067
  • 6
  • 39
  • 62

1 Answers1

0

The reason is you need PHP 5.4 or greater to achieve this functionality: per Parse error: syntax error, unexpected '[' with php 5.3

Community
  • 1
  • 1
Tyler Sebastian
  • 9,067
  • 6
  • 39
  • 62
  • In cases like this it is better to vote to close the question as a duplicate instead of answering it. Or if you don't have the rep for that, then leave a comment. – harmic Oct 11 '14 at 01:02