Created
June 21, 2026 08:52
-
-
Save dikiwidia/fca1eafb45627de8c6729fc819cd6596 to your computer and use it in GitHub Desktop.
Contoh Penerapan Array di PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Array Multidimensi Campuran Variatif (Kompleks) | |
| $transaksi_kompleks = [ | |
| "toko" => "TechUniverse Official", // Level 1 (String) | |
| "meta_data" => [ | |
| "status_aktif" => true, | |
| "tags" => ["elektronik", "gadget", "premium"] // Level 3 (Array Numerik biasa) | |
| ], | |
| "order" => [ | |
| "id_order" => "ORD-99821", | |
| "pengiriman" => [ | |
| "kurir" => "Sicepat Ekspres", | |
| "resi" => "REG-88219900", | |
| "tracking" => [ | |
| "status_terakhir" => "Paket dibawa kurir", | |
| "koordinat" => [-6.2088, 106.8456], // Level 5 (Array Numerik) | |
| "riwayat" => [ | |
| ["jam" => "08:00", "lokasi" => "Hub Jakarta Pusat", "noted" => "Sortir selesai"], | |
| ["jam" => "10:30", "lokasi" => "Drop Point Menteng", "noted" => "Dibawa kurir"] // Level 6 | |
| ] | |
| ] | |
| ], | |
| "pembayaran" => [ | |
| "metode" => "Kartu Kredit", | |
| "detail_cicilan" => [ | |
| "bank" => "BCA", | |
| "tenor_bulan" => 12, | |
| "bunga_persen" => 0, | |
| "simulasi_tagihan" => [ | |
| "pokok" => 1250000, | |
| "admin" => 5000 // Level 5 | |
| ] | |
| ] | |
| ], | |
| "items" => [ | |
| [ | |
| "nama" => "iPhone 15 Pro", | |
| "spek_pilihan" => [ | |
| "warna" => "Titanium Alami", | |
| "storage" => "256GB" // Level 5 | |
| ] | |
| ], | |
| [ | |
| "nama" => "iPhone 16 Pro", | |
| "spek_pilihan" => [ | |
| "warna" => "Rose Gold", | |
| "storage" => "512GB" // Level 5 | |
| ] | |
| ] | |
| ] | |
| ] | |
| ]; | |
| $meta_data = $transaksi_kompleks['meta_data']; | |
| $order = $transaksi_kompleks['order']; | |
| $items = $order['items']; | |
| $shipment = $order['pengiriman']; | |
| $payments = $order['pembayaran']; | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Produk</title> | |
| <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> | |
| </head> | |
| <body> | |
| <div class="flex w-full min-h-screen bg-sky-400 items-center justify-center"> | |
| <div class="flex flex-col rounded-lg overflow-auto w-1/3 min-h-90 bg-white shadow"> | |
| <div class="bg-slate-100 w-full py-4"> | |
| <h1 class="text-center font-bold text-2xl"><?php echo $transaksi_kompleks['toko']; ?></h1> | |
| <div class="flex items-center justify-center space-x-2 my-2"> | |
| <?php foreach ($meta_data['tags'] as $tag): ?> | |
| <span | |
| class="w-fit px-2 py-0.5 font-medium bg-rose-400 text-xs text-slate-50 rounded-full"><?php echo $tag; ?></span> | |
| <?php endforeach; ?> | |
| </div> | |
| </div> | |
| <div class="w-full p-4"> | |
| <div class="w-full flex items-start justify-between"> | |
| <h3 class="font-bold text-2xl flex-1"> | |
| <?php echo $order['id_order']; ?> | |
| </h3> | |
| <div class="flex-1 flex flex-col items-end text-right text-slate-600 uppercase"> | |
| <span class="font-bold"><?php echo $shipment['kurir']; ?></span> | |
| <span><?php echo $shipment['resi']; ?></span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="w-full px-4 py-2"> | |
| <h3 class="text-md font-bold bg-rose-400 px-2 w-fit rounded-full text-slate-50 my-1">Produk</h3> | |
| <table class="w-full border-collapse text-left"> | |
| <tr class="font-bold border border-slate-300 bg-slate-100"> | |
| <td rowspan="2" class="py-0.5 px-2 border border-slate-300">Item</td> | |
| <td colspan="2" class="py-0.5 px-2 border border-slate-300 text-center">Spesifikasi</td> | |
| </tr> | |
| <tr class="font-bold border border-slate-300 bg-slate-100"> | |
| <td class="py-0.5 px-2">Warna</td> | |
| <td class="py-0.5 px-2">Storage</td> | |
| </tr> | |
| <?php foreach ($items as $item): ?> | |
| <tr class="text-slate-600"> | |
| <td class="py-0.5 px-2 border border-slate-200"><?php echo $item['nama']; ?></td> | |
| <td class="py-0.5 px-2 border border-slate-200"><?php echo $item['spek_pilihan']['warna']; ?> | |
| </td> | |
| <td class="py-0.5 px-2 border border-slate-200"><?php echo $item['spek_pilihan']['storage']; ?> | |
| </td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </table> | |
| </div> | |
| <div class="w-full px-4 py-2"> | |
| <h3 class="text-md font-bold bg-rose-400 px-2 w-fit rounded-full text-slate-50 my-1">Riwayat Pengiriman | |
| </h3> | |
| <table class="w-full border-collapse text-left"> | |
| <tr class="font-bold border border-slate-300 bg-slate-100"> | |
| <td class="py-0.5 px-2 border border-slate-300">Jam</td> | |
| <td class="py-0.5 px-2 border border-slate-300 text-center">Lokasi</td> | |
| <td class="py-0.5 px-2 border border-slate-300 text-center">Catatan</td> | |
| </tr> | |
| <?php foreach ($shipment['tracking']['riwayat'] as $history): ?> | |
| <tr class="text-slate-600"> | |
| <td class="py-0.5 px-2 border border-slate-200"> | |
| <?php echo $history['jam']; ?> | |
| </td> | |
| <td class="py-0.5 px-2 border border-slate-200"> | |
| <?php echo $history['lokasi']; ?> | |
| </td> | |
| <td class="py-0.5 px-2 border border-slate-200"> | |
| <?php echo $history['noted']; ?> | |
| </td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </table> | |
| </div> | |
| <div class="bg-slate-100 w-full py-4"> | |
| <p class="text-center text-slate-600 text-sm"> | |
| copyright salman & albu <?php echo date('Y'); ?> | |
| </p> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment