How can PHP developers effectively use mysqli_result::fetch_array with different result types to avoid duplicate entries?

When using mysqli_result::fetch_array with different result types, PHP developers can effectively avoid duplicate entries by checking if the result type is associative or numerical before fetching the data. By using an if statement to determine the result type, developers can fetch the data accordingly to prevent duplicates.

$query = "SELECT * FROM table";
$result = $mysqli->query($query);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_array()) {
        if (is_numeric(array_keys($row)[0])) {
            // Numerical result type
            $value = $row[0];
        } else {
            // Associative result type
            $value = $row['column_name'];
        }
        // Use $value as needed
    }
}