Inspekt\Inspekt::isOneOf PHP Method

isOneOf() public static method

Returns true if value is one of $allowed, false otherwise.
public static isOneOf ( mixed $value, array | string $allowed ) : boolean
$value mixed
$allowed array | string
return boolean
    public static function isOneOf($value, $allowed)
    {
        /**
         * @todo: Consider allowing a string for $allowed, where each
         * character in the string is an allowed character in the
         * value.
         */
        if (is_string($allowed)) {
            $allowed = str_split($allowed);
        }
        return in_array($value, $allowed);
    }

Usage Example

Beispiel #1
0
 /**
  *
  */
 public function testIsOneOf()
 {
     $oneof = '<>\'"&';
     $input = '&';
     $this->assertTrue(Inspekt::isOneOf($input, $oneof));
 }