ulvis.paste.net

Paste Search Dynamic
Recent pastes
contains
  1. <?php
  2.  
  3. class Entree {
  4.     public $name;
  5.     public $ingredients = array();
  6.     public function hasIngredient($ingredient) {
  7.         return in_array($ingredient, $this->ingredients);
  8.     }
  9. };
  10.  
  11. $soup = new Entree;
  12. $soup->name = 'Chicken Soup';
  13. $soup->ingredients = array('chicken', 'water');
  14.  
  15. $sandwich = new Entree;
  16. $sandwich->name = 'Chicken Sandwich';
  17. $sandwich->ingredients = array('chicken', 'bread');
  18.  
  19. foreach (['chicken', 'lemon', 'bread', 'water'] as $ing) {
  20.     if ($soup->hasIngredient($ing)) {
  21.         print "Soup contains $ing.\n";
  22.     }
  23.     if ($sandwich->hasIngredient($ing)) {
  24.         print "Sandwich contains $ing.\n";
  25.     }
  26. }
Parsed in 0.026 seconds