This seems to be based entirely on a misunderstanding. See this quote, highlight mine:
1 – You are wasting speed if you reference the values, but don’t use quotes. According to Reinhold Weber’s Blog: #17: “$row[’id’]
is 7 times faster than $row[id]
“. If you’re doing this a lot, and often… ouch.
Yes, $row['id']
is faster than $row[id]
, because $row[id]
is a syntax error, which tries to resolve a constant, then turns it into a string, and throws a notice at the same time. But $row[1]
and $row['id']
are both valid and should perform very much identical. If there's a difference between looking up a numeric index and looking up a string index it must be so minimal as to be not worth your time.
The revelation that PHP arrays don't really have positional keys but are all associative is... not really news, and there are no wide-spread speed problems because of this. In fact, this quick benchmark shows that "numeric string" indexes are easily the slowest lookup of all of them: http://codepad.org/aeNJ2u3O
Anyway, you should be using mysql_fetch_assoc
or mysql_fetch_row
, which gets you a named (string indexes) or an unnamed (numeric indexes) array respectively. Using _fetch_array
, which gets you both, is usually unnecessary.
If you want real performance data, benchmark it for your use case.
mysql_fetch_array()
, as the underlying array implementation within PHP handles fetching a value for a given key."id"
if you input0
. These are two separate keys with separate data, and the lookup times for each are in no way connected.