How can PHP developers optimize their code when using IF statements in MySQL queries?

When using IF statements in MySQL queries, PHP developers can optimize their code by using the MySQL CASE statement instead. This can help improve readability and performance of the query.

$query = "SELECT 
            id, 
            name, 
            CASE 
              WHEN age < 18 THEN 'Minor' 
              ELSE 'Adult' 
            END AS age_group 
          FROM users";
$result = mysqli_query($connection, $query);

while($row = mysqli_fetch_assoc($result)) {
    echo $row['id'] . ' - ' . $row['name'] . ' - ' . $row['age_group'] . '<br>';
}