Imagine you have a list of fruit from a database in your hand. PHP allows you to access this data in two
different ways, depending on how you set the "switch" in the fetch function.
EXAMPLE
RESULT
The result will be displayed here...
Numeric Mode (Default): The computer tells itself: "The first column is 0, the second is 1."
To get an apple, we have to write $row[0].
Associative Mode (MYSQLI_ASSOC): The computer uses the column names that we defined
ourselves in the database. Instead of a number, we write $row['fruit'].
Why do we almost always use MYSQLI_ASSOC in practice?
Readability: You immediately know what you are outputting, even if you open the code a year
from now.
Safety during modifications: If you add a new column to the database, your code won't
crash because you are still referring to the same column name.
We use cookies to ensure a better user experience and website functionality.