You are on page 1of 5

Array (Lanjutan)

PERTEMUAN KEENAM
MATA KULIAH DASAR PEMROGRAMAN
Kamis, 29 April 2021

Oleh:
Budi Sunaryo, S.T., M.T.
Dosen Program Studi Teknologi Rekayasa Komputer Jaringan
Fakultas Teknologi Industri, Universitas Bung Hatta
www.sunaryo.id
https://bunghatta.ac.id | budi.sunaryo@bunghatta.ac.id
081320777313
Latihan

https://bunghatta.ac.id | budi.sunaryo@bunghatta.ac.id
Source Code

1. <?php
2. $nilai = array("Hagus Hermanto"=>90, "Nilam Darma Taksiah"=>85, "Fadly Kurniawan"=>70,
"Joni Sukma Wardana"=>60, "Muhammad Ridho Aulia"=>50, "Reihan Hanafi Wiyanatra"=>75);
3. $heads = array("No", "Nama", "Nilai", "Kelulusan");
4. ?>
5. <h2 align="center">Daftar Nilai Mahasiswa</h2>
6. <table align="center" border="1">
7. <thead>
8. <tr>
9. <?php
10.foreach ($heads as $key) {
11.echo "<th>" . $key . "</th>";
12.}
13.?>
14.</tr>
15.</thead>
16.<tbody>
3

https://bunghatta.ac.id | budi.sunaryo@bunghatta.ac.id
Source Code (lanjutan)

17.<?php
18.$nomor = 1;
19.foreach ($nilai as $nama => $skor) {
20.echo "<tr>";
21.echo "<td>" . $nomor . "</td>";
22.echo "<td>" . $nama . "</td>";
23.echo "<td>" . $skor . "</td>";
24.echo "<td>";
25.if($skor > 55) { echo "Lulus"; }
26.else { echo "Tidak Lulus"; }
27.echo "</td>";
28.echo "</tr>";
29.$nomor++;
4

https://bunghatta.ac.id | budi.sunaryo@bunghatta.ac.id
Source Code (lanjutan)

30.}
31.$total = array_sum($nilai);
32.$rata = $total/count($nilai);
33.$rata2 = number_format($rata, 2, '.', '');
34.echo "<tr>";
35.echo "<th colspan='2'>Rata-rata</th>";
36.echo "<th colspan='2'>" . $rata2 ."</th>";
37.echo "</tr>";
38.?>
39.</tbody>
40.<tfoot>
41.<tr>
42.<th colspan="4">Data Nilai Mahasiswa TRKJ, Mata Kuliah Dasar Pemrograman Tahun
2021</th>
43.</tr>
44.</tfoot>
45.</table>
5

https://bunghatta.ac.id | budi.sunaryo@bunghatta.ac.id

You might also like