What are the differences between mysqli_fetch_array and mysqli_fetch_assoc in PHP?

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

// Using mysqli_fetch_array
$result = mysqli_query($conn, "SELECT * FROM users");
while($row = mysqli_fetch_array($result)) {
    echo $row['username'] . " - " . $row[1] . "<br>";
}

// Using mysqli_fetch_assoc
$result = mysqli_query($conn, "SELECT * FROM users");
while($row = mysqli_fetch_assoc($result)) {
    echo $row['username'] . " - " . $row['email'] . "<br>";
}