How can if conditions be properly integrated within a foreach loop in PHP?

When integrating if conditions within a foreach loop in PHP, it is important to place the if statement inside the loop to check each element as it iterates. This allows for conditional logic to be applied to each element of the array or collection being looped through.

// Example of integrating if conditions within a foreach loop in PHP

$numbers = [1, 2, 3, 4, 5];

foreach ($numbers as $number) {
    if ($number % 2 == 0) {
        echo $number . " is even <br>";
    } else {
        echo $number . " is odd <br>";
    }
}