-2

Parse error: syntax error, unexpected '[' on line 108

$row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : [];

This is the error i am getting but works fine on the local server. I am trying to run the explode function on hostgator server with PHP 5.3 version.

here's the code for which i am getting this parse error.

while($row = $articlesQuery->fetch_object()) {
    $row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : [];
    $articles[] = $row;
}

please help

Thanks in advance.

3
  • Short array syntax [] has support from PHP5.4+ Commented Nov 24, 2014 at 19:33
  • so how to get this code work in PHP 5.3? bcoz hostgator does not have PHP 5.4 or a higher version Commented Nov 24, 2014 at 19:37
  • 1
    Just use traditional array() instead. Commented Nov 24, 2014 at 19:42

1 Answer 1

0

[] notation for arrays is only supported in PHP 5.4+, try this if you're using a lower version :

while($row = $articlesQuery->fetch_object()) {
    $row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : array();
    $articles[] = $row;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Many Thanks @Maxiwheat it worked and I also requested my hosting server company to upgrade PHP to 5.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.