Newer
Older
hello-programmer-world / src / sample / php / if.php
@h.sakamoto h.sakamoto 8 days ago 1 KB php
<?php 
$messages = [
    [
        "priority" => "high",
        "message" => "社長の胸ポケットに入っていたのは、なんとネギでした",
    ],
    [
        "priority" => "normal",
        "message" => "会議は予定通り進行中です",
    ],
    [
        "priority" => "low",
        "message" => "第二種電気工事士に合格しました",
    ]
];
?>
<!DOCTYPE html>
<style>
.priority-high {
    font-weight: bold;
    color: red;
}
.priority-normal {
    color: black;
}
.priority-low {
    color: gray;
}
</style>
<table border="1">
    <tr>
        <th>重要度</th>
        <th>メッセージ</th>
    </tr>
    <?php foreach ($messages as $msg): ?>
    <tr>
        <td>
            <?php if ($msg["priority"] === "high"): ?>
                <strong class="priority-high">高</strong>
            <?php elseif ($msg["priority"] === "low"): ?>
                <span class="priority-low">低</span>
            <?php else: ?>
                <span class="priority-normal">中</span>
            <?php endif; ?>
        </td>
        <td><?php echo $msg["message"]; ?></td>
    </tr>
    <?php endforeach; ?>
</table>