Download the PHP package ensostudio/comparator without Composer
On this page you can find all versions of the php package ensostudio/comparator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download ensostudio/comparator
More information about ensostudio/comparator
Files in ensostudio/comparator
Download ensostudio/comparator
More information about ensostudio/comparator
Files in ensostudio/comparator
Vendor ensostudio
Package comparator
Short Description The flexible comparation of any values
License BSD-3-Clause
Homepage https://github.com/ensostudio/comparator
Package comparator
Short Description The flexible comparation of any values
License BSD-3-Clause
Homepage https://github.com/ensostudio/comparator
Please rate this library. Is it a good library?
Informations about the package comparator
The flexible comparation of
- index/assoc arrays
- objects/closures
- floats/NANs
- binary/text strings
- stream resources
Installation
Via Composer:
composer require ensostudio/comparator
Usage
use EnsoStudio\Comparator\Comparator;
$comparator = Comparator(Comparator::EQUAL_ARRAY | Comparator::EQUAL_FLOAT);
if ($comparator->compare($value, $value2)) {
echo 'same values';
}
$comparator->setFlags(Comparator::EQUAL_FLOAT);
var_dump(3 - 2.4 == 0.6, $comparator->compare(3 - 2.4, 0.6));
// false, true
$comparator->setFlags(Comparator::EQUAL_STRING);
var_dump('foo' == 'FOO', $comparator->compare('foo', 'FOO'));
// false, true
// Case-issensetive comparation supports only for English:
var_dump($comparator->compare('я', 'Я'));
// false
$comparator->setFlags(Comparator::EQUAL_CLOSURE);
$createClosure = function () {
return function ($value) {
return $value * 2;
};
};
var_dump($createClosure() == $createClosure(), $comparator->compare($createClosure(), $createClosure()));
// false, true
$comparator->setFlags(Comparator::EQUAL_ARRAY | Comparator::EQUAL_FLOAT);
var_dump($comparator->compare(
['float' => 2 - 1.6, 'int' => 3],
['int' => 3, 'float' => 0.4]
));
// true
Public API
namespace EnsoStudio\Comparator;
class Comparator
{
public function __construct(int $flags);
public function setFlags(int $flags);
public function getFlags(): int;
public function hasFlag(int $flag): bool;
public function getType(mixed $value): string;
public function canCompare(string $type, string $type2): bool;
public function compare(mixed $value, mixed $value): bool;
}All versions of comparator with dependencies
PHP Build Version
Package Version
Requires
php Version
>=7.2
The package ensostudio/comparator contains the following files
Loading the files please wait ...