PHP code example of adeptoas / sniff-array

1. Go to this page and download the library: Download adeptoas/sniff-array 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/ */

    

adeptoas / sniff-array example snippets


__construct(array $spec, bool $throw = false)

sniff(array $array): bool

static arrayConformsTo(array $spec, array $data, bool $throw = false): bool

static forType(string $type): SplSniffer

sniff(mixed $val, bool $isStrict = false): bool

[
    'key'       =>  'string',
    'otherKey'  =>  'int'
]

[
    'key'       =>  'value',
    'otherKey'  =>  42
]

[
    'key'   =>  [
        'first'     =>  'number',
        'second'    =>  'bool'
    ]
]

[
    'key'   =>  [
        'first'     =>  INF,
        'second'    =>  false
    ]
]

[
    'key'   =>  'someString'
]

[
    'key'       =>  'string',
    'optional?' =>  'int',
    'any*'      =>  [
        'foo'   =>  'bool',
        'bar'   =>  [
            'one+'      =>  'number!',
            'two{3,5}'  =>  'number!'
        ]
    ]
]

[
    'key'       =>  'value',
    'optional'  =>  0,
    'any'       =>  [
        [
            'foo'   =>  true,
            'bar'   =>  [
               'one'   =>  123,
               'two'   =>  [456, 789, 321, 654]
            ]
        ], [
            'foo'   =>  false,
            'bar'   =>  [
               'one'   =>  [3.141592, 6.283185],
               'two'   =>  [1.414213, 2.718281, 1.618033]
            ]
        ]
    ]
]

[
    'key'       =>  'value',
    'any'       =>  [
        'foo'   =>  true,
        'bar'   =>  [
            'one'   =>  123,
            'two'   =>  [1.1, 2, 3.3, 4, 5.5]
        ]
    ]
]

[
    'key'       =>  'string!|bool',
    'otherKey'  =>  'int|array'
]

[
    'key'       =>  'element',
    'otherKey'  =>  123
]

[
    'key'       =>  true,
    'otherKey'  =>  123
]

[
    'key'       =>  false,
    'otherKey'  =>  ['foo', 'bar']
]

[
    '__root+'   =>  [
        'foo'       =>  'bool',
        'bar?'      =>  'int'
    ]
]

[
    [
        'foo'   =>  'true',
        'bar'   =>  0
    ], [
        'foo'   =>  'true'
    ], [
        'foo'   =>  'false',
        'bar'   =>  42
    ]
]

[
    'foo*'   =>  'string::^[A-Z][a-z]*$'
]

[
    'foo'   =>  ['Hello', 'World']
]

[
    'foo'   =>  ['eHlo', 'World', '!']
]

[
    'object'   =>  'class::MyClass'
]

[
    'object'   =>  new MyClass()
]

[
    'object'   =>  new MyOtherClass()
]

[
    'object'   =>  new stdClass()
]

[
    'object'   =>  'class::MyClass::MyOtherClass'
]

[
    'object'   =>  new MyClass()
]

[
    'object'   =>  new MyOtherClass()
]

[
    'values'   =>  'array::sequential'
]

[
    'values'    =>  [1, 2, 'one', 'two', true, false]
]

[
    'values'    =>  [
        'key'   =>  'value'
    ]
]

[
    'dict'   =>  'array::associative'
]

[
    'dict'  =>  [
        'one'   =>  1,
        'two'   =>  2
    ]
]

[
    'members'   =>  'array::seq',
    'relations' =>  'array::assoc'
]