Possible Duplicate:
Access array returned by a function in php
The code:
$cnt = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()"))[0]
Is giving the error:
Parse error: syntax error, unexpected ‘[‘ in
index.php on line 117
Same for:
$cnt = (mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()")))[0]
This code:
$cnt = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()"));
$cnt = $cnt[0];
is working fine.
What’s going on here?
It isn’t just a problem with
mysql_query–rather, it’s an idiosyncracy in the way that PHP <5.4 handles bracket notation. The following will fail, as well:But, as you observed, setting the result before attempting to retrieve an element works fine: