What is the difference between mysql_fetch_array and mysql_fetch_assoc in PHP?

The main difference between mysql_fetch_array and mysql_fetch_assoc in PHP is the way they return data from a MySQL database query. mysql_fetch_array returns data as both a numerical and associative array, while mysql_fetch_assoc only returns data as an associative array. If you only need to access data by column names, mysql_fetch_assoc is more efficient to use.

// Using mysql_fetch_assoc to fetch data from a MySQL database query
$result = mysql_query("SELECT * FROM table");
while($row = mysql_fetch_assoc($result)) {
    echo $row['column_name'];
}