How can PHP developers effectively differentiate between a single row and an array of results when processing database queries?

When processing database queries in PHP, developers can differentiate between a single row and an array of results by checking the number of rows returned by the query. If the query returns only one row, it can be accessed directly as an associative array. If the query returns multiple rows, the results will be stored in an array of associative arrays.

// Assuming $result is the result of a database query

if ($result->num_rows == 1) {
    // Single row returned
    $row = $result->fetch_assoc();
    // Access data using $row['column_name']
} else {
    // Multiple rows returned
    while ($row = $result->fetch_assoc()) {
        // Access data using $row['column_name']
    }
}