<?php
//pertama yg ku pakai adalah array assosiatif untuk nyimpan daftar dan status kursi
"A1" => false, //A1-B3 =kuncinya //false (aku pakai FALSE karna kursinya belum dipesan)
"A2" => false,
"A3" => false,
"B1" => false,
"B2" => false,
"B3" => false,
);
$hargaTiket = 35.000; //variabel menentukan harga per kursinya
$kursiDipilih = array("A2", "B3", "A1"); //array bisa diisi sesuai pesanan function prosespemesanan($kursi , $kursiDipilih) {
foreach ($kursiDipilih as $k) {
if (isset($kursi[$k]) && !$kursi[$k]) { $kursi[$k] = true;
$berhasil[] = $k;
} else {
$gagal[] = $k;
}
}
return array("berhasil" => $berhasil, "gagal" => $gagal); }
function hitungTotalHarga($jumlahKursi, $hargaTiket) {
return $jumlahKursi * $hargaTiket;
}
$result = prosespemesanan($kursi, $kursiDipilih);
$totalHarga = hitungTotalHarga
(count($result["berhasil"]), $hargaTiket); echo "Rincian Reservasi:<br>";
if (!empty($result["berhasil"])) { echo "Kursi Berhasil Dipesan: " . implode(", ", $result["berhasil"]) . "<br>"; echo "Total Harga: Rp$totalHarga<br>";
} else {
echo "Tidak ada kursi yang berhasil dipesan.<br>";
}
if (!empty($result["gagal"])) { echo "Kursi Tidak Tersedia: " . implode(", ", $result["gagal"]) . "<br>"; }
// Menampilkan status semua kursi
echo "<br>Status Kursi:<br>";
foreach ($kursi as $key => $status) {
echo "$key: " . ($status ? "Sudah Dipesan" : "Tersedia")."<br>";
}
?>
PD9waHAKLy9wZXJ0YW1hIHlnIGt1IHBha2FpIGFkYWxhaCBhcnJheSBhc3Nvc2lhdGlmIHVudHVrIG55aW1wYW4gZGFmdGFyIGRhbiBzdGF0dXMga3Vyc2kKJGt1cnNpID0gYXJyYXkoCiAgICAiQTEiID0+IGZhbHNlLCAvL0ExLUIzID1rdW5jaW55YSAvL2ZhbHNlIChha3UgcGFrYWkgRkFMU0Uga2FybmEga3Vyc2lueWEgYmVsdW0gZGlwZXNhbikKICAgICJBMiIgPT4gZmFsc2UsCiAgICAiQTMiID0+IGZh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