PHP code example of aegisora / in-array-rule

1. Go to this page and download the library: Download aegisora/in-array-rule library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aegisora / in-array-rule example snippets


in_array($value, $array, $strict)

use Aegisora\Rules\InArrayRule;
use Aegisora\RuleContract\Models\Context;

$rule = InArrayRule::create(['apple', 'banana', 'orange',]);

$result = $rule->validate(Context::create('banana'));

if ($result->isValid()) {
    // value exists in array
} else {
    // value not found
}

$rule = InArrayRule::create([1, 2, 3,]);

$rule->validate(Context::create('1')); // false

$rule = InArrayRule::createSoft([1, 2, 3,]);

$rule->validate(Context::create('1')); // true

InArrayRule::create($array);         // strict by default
InArrayRule::createStrict($array);   // explicit strict
InArrayRule::createSoft($array);     // loose comparison