How can a PHP beginner effectively incorporate a loop with conditional statements to format output in a specific way?

To effectively incorporate a loop with conditional statements to format output in a specific way, a PHP beginner can use a foreach loop to iterate through an array of data and use if statements within the loop to apply formatting based on certain conditions. By checking each element in the array and applying formatting rules as needed, the output can be customized according to the specified requirements.

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

foreach ($data as $value) {
    if ($value % 2 == 0) {
        echo "<p>$value is even</p>";
    } else {
        echo "<p>$value is odd</p>";
    }
}