How can PHP be used to calculate and display percentage values in a visually appealing way, such as with color-coded progress bars?

To calculate and display percentage values in a visually appealing way using PHP, you can create color-coded progress bars. This can be achieved by calculating the percentage value, setting up different colors based on the percentage range, and displaying the progress bar with the corresponding color.

<?php
$percentage = 75; // Example percentage value
$color = 'green'; // Default color

if ($percentage < 25) {
    $color = 'red';
} elseif ($percentage >= 25 && $percentage < 50) {
    $color = 'orange';
} elseif ($percentage >= 50 && $percentage < 75) {
    $color = 'yellow';
}

echo '<div style="background-color: ' . $color . '; width: ' . $percentage . '%; height: 20px;"></div>';
?>