fork download
  1. <?php
  2. // array asosiatif untuk menyimpan data produk
  3. $produk = [
  4. ["nama" => "Laptop", "harga" => 15000000],
  5. ["nama" => "Smartphone", "harga" => 7000000],
  6. ["nama" => "Headphone", "harga" => 500000],
  7. ["nama" => "Smartwatch", "harga" => 2000000],
  8. ["nama" => "Tablet", "harga" => 4000000]
  9. ];
  10.  
  11. // Menampilkan daftar produk
  12. echo "<h2>Daftar Produk</h2>\n";
  13. echo "<ul>";
  14. foreach ($produk as $item) {
  15. echo "<li>" . $item['nama'] . " - Rp " . number_format($item['harga'], 0, ',', '.') . "</li>";
  16. }
  17. echo "</ul>";
  18. ?>
  19.  
Success #stdin #stdout 0.02s 26236KB
stdin
Standard input is empty
stdout
<h2>Daftar Produk</h2>
<ul><li>Laptop - Rp 15.000.000</li><li>Smartphone - Rp 7.000.000</li><li>Headphone - Rp 500.000</li><li>Smartwatch - Rp 2.000.000</li><li>Tablet - Rp 4.000.000</li></ul>