'Nguyễn Văn An', 'score' => 8.5], ['name' => 'Trần Thị Bình', 'score' => 9.2], ['name' => 'Lê Hoàng Cường', 'score' => 7.8], ['name' => 'Phạm Minh Dung', 'score' => 9.0], ]; } if (isset($_GET['reset'])) { unset($_SESSION['bai18_students']); header('Location: index.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $score = isset($_POST['score']) && is_numeric($_POST['score']) ? (float)$_POST['score'] : -1; if ($name !== '' && $score >= 0 && $score <= 10) { $_SESSION['bai18_students'][] = ['name' => $name, 'score' => $score]; } } function findTopStudent(array $students): ?array { if (empty($students)) return null; $top = $students[0]; foreach ($students as $st) { if ($st['score'] > $top['score']) { $top = $st; } } return $top; } $students = $_SESSION['bai18_students']; $topStudent = findTopStudent($students); ?>
| # | Họ và tên | Điểm số |
|---|---|---|
| = $i + 1 ?> | = htmlspecialchars($st['name']) ?> | = number_format($st['score'], 1) ?> |