Anda di halaman 1dari 11

LAPORAN TUGAS PRAKTIKUM

PENGEMBANGAN APLIKASI WEB


MODUL 3

Disusun Oleh:
Nama: Toba Jordi Naibaho
NIM: 190411100115
Kelas: PAW B
Dosen Pengampu:
Nama: Devie Rosa Anamisa, S.Kom., M.Kom.
NIP: 19841104 200812 2 003
Asisten Praktikum:
Nama: Dimas Dliyaur Rahman
NIM: 210411100080

PRODI TEKNIK INFORMATIKA


JURUSAN TEKNIK INFORMATIKA
FAKULTAS TEKNIK
UNIVERSITAS TRUNOJOYO MADURA
2023
1. Code Program
<h1 style="text-align: center;">Script 1</h1>
<?php
$fruits = array("Avocado", "Blueberry", "Cherry");

function tambah() {
global $fruits;
array_push($fruits,"Banana","Mango","Strawberry","Pine
apple","kiwi");
$arrlength = count($fruits);
for($x = 0; $x < $arrlength; $x++) {
echo $fruits[$x] . " => $x"; echo
"<br>";
}
echo "<hr>";
}

function kurang(){
global $fruits;
// Hapus element
unset($fruits[3]);
// pengindeks an ulang
$fruits = array_values($fruits);
// Menghitung ulang panjang array setelah pengindeksan
ulang
$arrlength = count($fruits);

for ($x = 0; $x < $arrlength; $x++) {


echo $fruits[$x] . " => $x"; echo
"<br>";
}
echo "<hr>";
}

function databaru() {
$vegies = array ("Wortel","Bayam","Kangkung");
$arrlength = count($vegies);

for ($x = 0; $x < $arrlength; $x++) {


echo $vegies[$x] . " => $x"; echo
"<br>";
}
echo "<hr>";
}
tambah();
kurang();
databaru();
Penjelasan Code Program:
1. indeks tertinggi dari array tersebut setelah ditambah dengan data baru adalah 7
2. indeks tertinggi dari array tersebut setelah dihapus adalah 6

Hasil Running Program:


2. Code Program
<h1 style="text-align: center;">Script 2</h1>
<?php
$fruits = array("Avocado", "Blueberry", "Cherry");
// Tambah 5 data baru
function tambah_data_5() {
global $fruits;

for ($i = 1; $i <= 5; $i++) {


$fruits[] = "New Fruit " . $i;
}

$arrlength = count($fruits);

for ($x = 0; $x < $arrlength; $x++) {


echo $fruits[$x] . " => $x"; echo
"<br>";
}
echo "<hr>";
}
// Data baru
function data_baru() {
$vegies = array("kentang","bayam","tomat");
$arrlength = count($vegies);
for($x = 0; $x < $arrlength; $x++) {
echo $vegies[$x];
echo "<br>";
}
echo "<hr>";
}
tambah_data_5();data_baru();
?>

Penjelasan Code Program:


4. Saat ini array $fruits mempunyai Panjang data sebanyak 7 yang dimulai
dari 0. Perlu dilakukan beberapa perubahan dikarenakan saya akan
menampilkan indeks pada data tersebut. Perubahan dilakukan pada bagian
for ($x = 0; $x < $arrlength; $x++) {
echo $fruits[$x] . " => $x"; echo
"<br>";
}
echo "<hr>";
5. iya, saya melakukan beberapa modifikasi dikarenakan pada bagian script
data array Bernama variable $fruits sedangkan pada script saya Bernama
$vegies.

Hasil Running Program:


3. Code Program
<h1 style="text-align: center;">Script 3</h1>
<?php
$height = array("Andy"=>"176", "Barry"=>"165",
"Charlie"=>"170");
// menambahkan lima data barufunction
Lima_Data_Baru() {
global $height;
$height["Adi"] = "180";
$height["Ridwan"] = "162";
$height["Zainal"] = "175";
$height["Kiboy"] = "168";
$height["Naruto"] = "172";

echo "indeks akhir adalah ".array_key_last($height) ."


tinggi " .end($height);
echo "<br>";
echo "<hr>";

function hapus() {
global $height;
unset($height["Adi"]);
echo "Indeks terakhir setelah menghapus data Adi adalah "
. array_key_last($height) . " tinggi " . end($height);
echo "<br>";
echo "<hr>";
}

function weight() {
$height["Adi"] = "70";
$height["Ridwan"] = "65";
$height["Zainal"] = "90";

// cetak semua array


foreach ($height as $nama => $tinggi) {
echo "Nama: " . $nama . ", Tinggi: " . $tinggi .
"<br>";
}
echo "<hr>";
}

Lima_Data_Baru();hapus();
weight();
Penjelasan Code Program:
6. menambahkan data baru terdapat pada function lima_Data_Baru()
7. menghapus data tertentu terdapat pada function hapus()
8. data baru terdapat pada function weight()

Hasil Running Program:


4. Code Program
<h1 style="text-align: center;">Script 4</h1>
<?php
$height = array("Andy"=>"176", "Barry"=>"165",
"Charlie"=>"170");
function tambah_data_baru() {
global $height;
$height["Adi"] = "180";
$height["Ridwan"] = "162";
$height["Zainal"] = "175";
$height["Kiboy"] = "168";
$height["Naruto"] = "172";

foreach($height as $x => $x_value) {


echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
echo "<hr>";
}

function weight_baru() {
$weight["Adi"] = "70";
$weight["Ridwan"] = "65";
$weight["Zainal"] = "90";

foreach($weight as $x => $x_value) {


echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
echo "<hr>";
}
tambah_data_baru();weight_baru();
?>

Penjelasan Code Program:


9. tidak
10. terjadi beberapa perubhana dikarenakan nama variable pada script lama
dengan script baru berbeda. Perbeddaan pada variable $weight
Hasil Running Program:
5. Code Program
<h1 style="text-align: center;">Script 5</h1>
<?php
$students = array( array("Alex","220401","0812345678"),
array("Bianca","220402","0812345687"),
array("Candice","220403","0812345665"),
);
function mahasiswa_baru() {
global $students;

$newData = array(
array("David", "220404", "0812345601"),
array("Ella", "220405", "0812345602"),
array("Frank", "220406", "0812345603"),
array("Grace", "220407", "0812345604"),
array("Hannah", "220408", "0812345605"),
);

$students = array_merge($students, $newData); for

($row = 0; $row < count($students); $row++) {


echo "<p><b>Row number $row</b></p>";
echo "<ul>";
for ($col = 0; $col < 3; $col++) {
echo "<li>" . $students[$row][$col] . "</li>";
}
echo "</ul>";
}
echo "<hr>";
}
mahasiswa_baru();
?>

<table border="1">
<thead>
<tr>
<th>Nama</th>
<th>NIM</th>
<th>Nomor Telepon</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student) : ?>
<tr>
<?php foreach ($student as $data) : ?>
<td><?= $data ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Penjelasan Code Program:

Hasil Running Program:

Anda mungkin juga menyukai