How can PHP be used to display names in colored circles or boxes based on a specific status?

To display names in colored circles or boxes based on a specific status in PHP, you can use CSS styling to create the colored circles or boxes and then dynamically apply the appropriate styles based on the status. This can be achieved by using conditional statements in PHP to determine the status and then outputting the name within the corresponding styled element.

<?php
// Sample array of names and statuses
$names = array(
    'Alice' => 'active',
    'Bob' => 'inactive',
    'Charlie' => 'pending'
);

// Loop through the names and statuses
foreach ($names as $name => $status) {
    // Determine the color based on status
    switch ($status) {
        case 'active':
            $color = 'green';
            break;
        case 'inactive':
            $color = 'red';
            break;
        case 'pending':
            $color = 'yellow';
            break;
        default:
            $color = 'black';
    }

    // Output the name within a colored circle
    echo "<div style='display: inline-block; width: 30px; height: 30px; border-radius: 50%; background-color: $color; text-align: center; line-height: 30px; margin-right: 10px;'>$name</div>";
}
?>