Do functions that print arrays all use the same notation to do so? What is the reasoning for one notation over another? I noticed when using PHP print_r to display an array compiled using mysql_fetch_array, the notation of the array is as follows:
Array ([column] => value [index] = value)
For example, if this is the table:
id fname lname
1 John Smith
Then the print_r output of mysql_fetch_array will be:
Array ([id] => 1 [0] => 1 [fname] => John [1] => John [lname] => Smith [2] => Smith)
What is the reason for this notation? Specifically, why does the value repeat? Isn’t that redundant?
Also, can anybody recommend a good resource for a better conceptual understanding of arrays in general? Thanks!
Associative arrays use strings for the index, numeric arrays use numbers.
mysql_fetch_array()creates an associative array containing numeric keys as well so that both may be used to access the array.mysql_fetch_assoc()creates an array containing only the string indices.mysql_fetch_row()creates an entirely numeric array, and is the fastest to execute of these functions.