Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * awal program ada input login, login statis
- * username: admin
- * password: admin123
- */
- /**
- * Setelah login tampil menu utama program
- * terdapat array, perungalan, percabangan, function (optional)
- */
- $username = "admin";
- $password = "admin123";
- $dataBarang = [
- [
- "nama_barang" => "RAM DDR4 8GB",
- "stok" => 20
- ],
- [
- "nama_barang" => "Flashdisk 64GB",
- "stok" => 35
- ],
- [
- "nama_barang" => "SSD 128 GB",
- "stok" => 10
- ],
- ];
- // Memasukkan username dan password
- echo "Masukkan username: ";
- $inputUsername = trim(fgets(STDIN));
- echo "Masukkan password: ";
- $inputPassword = trim(fgets(STDIN));
- if ($inputUsername === $username && $inputPassword === $password) {
- while (true) {
- echo "Menu Utama: \n";
- echo "1. Lihat data barang\n2. Tambah barang baru\n3. Keluar Program\n";
- echo "Masukkan pilihan menu: ";
- $pilih = trim(fgets(STDIN));
- if ($pilih == 1) {
- tampilData($dataBarang);
- } elseif ($pilih == 2) {
- tambahBarang($dataBarang);
- } elseif ($pilih == 3) {
- echo "Terima kasih\n";
- break;
- } else {
- echo "Menu tidak ada! ulangi. \n";
- }
- }
- } else {
- echo "Username dan Password yang anda masukkan salah! ulangi\n";
- }
- // function menampilkan data barang
- function tampilData($data) {
- echo "Data Barang\n\n";
- foreach ($data as $index => $tampil) {
- echo ($index+1) .". $tampil[nama_barang] sisa stok $tampil[stok]\n";
- }
- echo "\n";
- }
- // function tambah barang
- function tambahBarang(&$data) {
- echo "Masukkan nama barang: ";
- $namaBarang = trim(fgets(STDIN));
- echo "Masukkan stok barang: ";
- $stokBarang = trim(fgets(STDIN));
- $data[] = [
- "nama_barang" => $namaBarang,
- "stok" => $stokBarang
- ];
- echo "Data berhasil ditambah \n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement