<?php if (Term::create('oni')->in(['cheese', 'tomato', 'onion', 'pepperoni'])) { echo '"oni" is available in the given ingredients'.PHP_EOL; } else { echo '"oni" is NOT available in the given ingredients'.PHP_EOL; } if (Term::create('oni')->in('pepperoni')) { echo '"oni" is available in the given ingredient'.PHP_EOL; } else { echo '"oni" is NOT available in the given ingredient'.PHP_EOL; } // Pretend the following isn't here class Term { public $value; public function __construct($value) { $this->value = $value; } public static function create($value) { return new self($value); } public function in($search) { return array_reduce((array) $search, function ($carry, $item) { return $carry ?: (bool) mb_substr_count($item, $this->value); }); } public function notIn($search) { return !$this->in($array); } public function __toString() { return $this->value; } }
You have javascript disabled. You will not be able to edit any code.