Ketiklah kode berikut pada text editor simpan dengan nama array-demo1.php pada root direktori web server
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Praktikum 5. Array </title>
<meta http-equiv="content-typea" content="text/htmla;charset=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
//membuat array
$mahasiswa = array("Toni", "joko", "Agam", "Tina", "Lia", "Yana");
$ipk = array(3.23, 2.89, 4.00, 3.12, 3.12, 2.67, 2.22);
$i = 0;
//mengakses array
echo "<table border = 1>";
echo "<tr>";
echo "<td>No</td>";
echo "<td>Nama</td>";
echo "<td>IPK</td>";
echo "</tr>";
while ($nama = each($mahasiswa)){
echo "<tr>";
$no = $nama[0]+1;
echo "<td>$no</td>";
echo "<td>$nama[1]</td>";
echo "<td>$ipk[$i]</td>";
$i++;
}
echo "</table>";
?>
</body>
</html>
Output :
No comments:
Post a Comment