Restaurant.php - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Restaurant.php.php

  1. <?php
  2. // Restaurant.php 
  3.  
  4. class Restaurant {
  5.  
  6.   public $name;
  7.   public $menu;
  8.   public $inventory;
  9.   public $funds;
  10.  
  11.   public function __construct($name) {
  12.     $this->name = $name;
  13.     $this->menu = []; 
  14.     $this->inventory = [];
  15.     $this->funds = 1000; 
  16.   }
  17.  
  18.   public function addMenuItem($name, $price, $ingredients) {
  19.     $this->menu[] = new MenuItem($name, $price, $ingredients);
  20.   }
  21.  
  22.   public function buyIngredients($ingredients) {
  23.     // Check funds are sufficient
  24.     // Pay for ingredients
  25.     // Add to inventory
  26.   }
  27.  
  28.   public function cookItem($item) {
  29.     // Check ingredients are in inventory
  30.     // Deduct ingredients used
  31.     // Add completed dish to inventory
  32.   }
  33.  
  34.   // More functions for selling dishes, hiring staff, upgrades etc..
  35.  
  36. }
  37.  
  38. // MenuItem.php
  39.  
  40. class MenuItem {
  41.   
  42.   public $name;
  43.   public $price;
  44.   public $ingredients;
  45.   
  46.   public function __construct($name, $price, $ingredients) {
  47.     // Constructor 
  48.   }
  49.   
  50. }
  51. ?>
File Description
  • Restaurant.php
  • PHP Code
  • 26 Aug-2023
  • 944 Bytes
You can Share it: