Gives an error message

Parse error: syntax error, unexpected '[' in C: \ Server \ domains \ localhost \ test \ class_search.php on line 163 Line 163:

return '/'.$type.'/'.$r['res']->fetch_array(MYSQLI_NUM)[0].'/'.$uid.'/'; 
  • What version of PHP? - Anton Shchyrov

1 answer 1

Direct dereference of an array returned as a result of a function or method call is only possible from PHP 5.4. I suspect that you have a lower version, so you must first save the result returned by the fetch_array() method into a separate variable, and then refer to the zero element of the resulting value

 $row = $r['res']->fetch_array(MYSQLI_NUM); return '/'.$type.'/'.$row[0].'/'.$uid.'/';