This is not just a problem with mysql_query- rather, this idiosyncrasy is that PHP <5.4 handles the bracket notation. The following also does not work :
function get_array() {
return array('foo', 'bar');
}
echo get_array()[0];
But, as you noticed, setting the result before trying to extract the item works fine :
$arr = get_array();
echo $arr[0];
source
share