Parse error on explode function

378 views Asked by At

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.

1

There are 1 answers

1
MaxiWheat On BEST ANSWER

[] 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;
}