What is the potential issue with using mysqli_fetch_array instead of mysqli_fetch_assoc in PHP?

Using mysqli_fetch_array instead of mysqli_fetch_assoc in PHP can potentially cause issues because mysqli_fetch_array returns both numerical and associative keys for each row, which can lead to duplicate data retrieval and confusion when accessing values. To solve this issue, it is recommended to use mysqli_fetch_assoc, which only returns associative keys for each row, making it easier to access data.

// Connect to database
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Query database
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);

// Fetch data using mysqli_fetch_assoc
while ($row = mysqli_fetch_assoc($result)) {
    // Access data using associative keys
    echo $row['column_name'];
}

// Close connection
mysqli_close($conn);