Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Nama : Irhamda Abbas

Kelas : 19-A2
NPM : 19111100044
Matkul : KSI

Tugas PHP Contoh 13

1. Shourcode

<!DOCTYPE html>
<html lang="en">
<head>

<title>Belajar Array</title>

</head>
<body>
<h1>Latihan Array PHP</h1>
<h2>Array Terindex</h2>
<h3>Contoh Terindex Otomatis</h3>

<table border="1" width="60%"


style="border-collapse: collapse;
text-align: center;">
<th> Index
<?php for ($i=0;$i<=3;$i++){
echo "<th>$i</th>";

}
?>
</th>
<tr>
<th> Nilai </th>
<?php
$mobil = array("Toyota Avansa", "Toyota Corolla", "Suzuki Ertiga",
"Honda Civiv");
$y = count($mobil);
for($x=0; $x <$y ; $x++) {
echo "<td>";
echo $mobil[$x];

}
?>
</table>

<h3>Contoh index Ditentukan Manual</h3>

<table border="1" width="60%"


style="border-collapse: collapse;
text-align: center;">

<th> Index
<?php
$angka = array("2", "3", "8", "6");
$y = count($angka);
for($x=0; $x <$y ; $x++) {
echo "<td>";
echo $angka[$x];

}
?>
</th>
<tr>
<th> Nilai </th>
<?php
$mobil = array("Toyota Avansa", "Toyota Corolla", "Suzuki Ertiga", "Honda
Civiv");
$y = count($mobil);
for($x=0; $x <$y ; $x++) {
echo "<td>";
echo $mobil[$x];
}
?>
</table>

<h2>Array Asosiasi</h2>

<table border="1" width="15%"


style="border-collapse: collapse;">
<tr>
<th> Kunci </th>
<th> Nilai </th>
</tr>

<?php
$Kunci = array(
array ("Nama" => "Irhamda" , "Usia" => "17"),
array ("Nama" => "Cindy" , "Usia" => "18"),
array ("Nama" => "Sahara" , "Usia" => "19"),
array ("Nama" => "Andi" , "Usia" => "18"));
foreach($Kunci as $Nilai):
?>
<tr>
<td><?=$Nilai["Nama"]?></td>
<td><?=$Nilai["Usia"]?></td>
</tr>

<?php endforeach;?>
</table>
<h2>Array Multdimensi</h2>
<?php
$mobil3 = array (
array("suzuki","Ertiga","MPV"),
array("Toyota","Corolla","Sedan"),
array("Honda","Civic","Sedan")
);

?>
<table border="1" width="40%"
style="border-collapse: collapse;">
<tr>
<th>Vendor</th>
<th>Serie</th>
<th>Jenis</th>
</tr>
<?php
$n=count($mobil3);
for ($i=0; $i <$n ; $i++) {
$vendor = $mobil3[$i][0];
$seris = $mobil3[$i][1];
$jenis = $mobil3[$i][2];

?>
<tr>
<td><?=$vendor?></td>
<td><?=$seris?></td>
<td><?=$jenis?></td>
</tr>
<?php } ?>

Tampilan

You might also like