JBZoo\Data\Data::is PHP Method

is() public method

Compare value by key with somethig
public is ( string $key, mixed $compareWith = true, boolean $strictMode = false ) : boolean
$key string
$compareWith mixed
$strictMode boolean
return boolean
    public function is($key, $compareWith = true, $strictMode = false)
    {
        if (strpos($key, '.') === false) {
            $value = $this->get($key);
        } else {
            $value = $this->find($key);
        }
        if ($strictMode) {
            return $value === $compareWith;
        }
        return $value == $compareWith;
    }

Usage Example

Example #1
0
 public function testIs()
 {
     $data = new Data(array('key' => 1, 'nested' => array('key' => null)));
     isTrue($data->is('key'));
     isTrue($data->is('key', '1'));
     isTrue($data->is('key', 1));
     isTrue($data->is('key', true));
     isTrue($data->is('key', 1, true));
     isTrue($data->is('nested.key', null, true));
     isTrue($data->is('nested.key', false));
     isFalse($data->is('key', '1', true));
     isFalse($data->is('key', 1.0, true));
     isFalse($data->is('nested.key', '1', true));
     isFalse($data->is('nested.key', false, true));
 }