How can the PHP code be modified to organize the log entries into different categories as shown in the example image?

To organize the log entries into different categories, you can modify the PHP code by adding conditional statements based on the log message content. By checking the content of each log message, you can assign it to a specific category and display them accordingly. This can be achieved by using if-else statements or switch cases to categorize the log entries.

<?php
$logEntries = array(
    "Error: Database connection failed",
    "Warning: File not found",
    "Info: User logged in successfully",
    "Error: Invalid input data"
);

foreach ($logEntries as $log) {
    if (strpos($log, "Error") !== false) {
        echo "<p style='color: red;'>$log</p>";
    } elseif (strpos($log, "Warning") !== false) {
        echo "<p style='color: orange;'>$log</p>";
    } elseif (strpos($log, "Info") !== false) {
        echo "<p style='color: blue;'>$log</p>";
    } else {
        echo "<p>$log</p>";
    }
}
?>