maxlzp / range
使用范围替代值对
dev-master
2021-02-05 13:46 UTC
Requires
- php: ^7.2
- ramsey/collection: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.3.3
This package is auto-updated.
Last update: 2024-09-05 21:36:56 UTC
README
可以使用值对替代。 更多关于区间
安装
使用composer
composer require maxlzp/range
用法
创建范围
$range = Range::between($start, $end); $range = Range::betweenOpen($start, $end); $range = Range::betweenLeftOpen($start, $end); $range = Range::betweenRightOpen($start, $end); $range = Range::greaterThan($value); $range = Range::greaterOrEqualThan($value); $range = Range::lessThan($value); $range = Range::lessOrEqualThan($value);
检索范围属性
$left = $range->getLeft(); $right = $range->getRight(); $isEmpty = $range->isEmpty(); $width = $range->getWidth();
一些功能
$gap = $range->gap($otherRange); //Gap between two ranges $includes = $range->includes($otherRange); //Check if the range includes other range completely $includesValue = $range->includesValue($value); //Check if the value lays within the range $split = $range->splitAt($value); //Split the range into two ranges $touches = $range->touches($otherRange); //Check if ranges are touching one another