sebastian/comparator

提供比较 PHP 值是否相等的功能

6.1.0 2024-09-11 15:42 UTC

README

Latest Stable Version CI Status codecov

sebastian/comparator

此组件提供了比较 PHP 值是否相等的功能。

安装

您可以使用 Composer 将此库作为本地、按项目依赖项添加到项目中

composer require sebastian/comparator

如果您只需要在开发期间使用此库,例如运行项目的测试套件,那么您应该将其添加为开发时依赖项

composer require --dev sebastian/comparator

用法

<?php
use SebastianBergmann\Comparator\Factory;
use SebastianBergmann\Comparator\ComparisonFailure;

$date1 = new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York'));
$date2 = new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago'));

$factory = new Factory;
$comparator = $factory->getComparatorFor($date1, $date2);

try {
    $comparator->assertEquals($date1, $date2);
    print "Dates match";
} catch (ComparisonFailure $failure) {
    print "Dates don't match";
}