1. Go to this page and download the library: Download jstewmc/interval 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/ */
jstewmc / interval example snippets
use Jstewmc\Interval;
// create an interval between 2 (exclusive) and 4 (inclusive)
$interval = new Interval('(2, 4]');
// compare values
$interval->compare(1); // returns -1
$interval->compare(2); // returns -1
$interval->compare(3); // returns 0
$interval->compare(4); // returns 0
$interval->compare(5); // returns 1
// echo the interval
echo $interval; // returns "(2, 4]"
use Jstewmc\Interval;
$a = new Interval('(2, 4]');
$b = (new Interval())
->setLowerExclusive()
->setLower(2)
->setUpper(4)
->setUpperInclusive();
$a == $b; // returns true
use Jstewmc\Interval;
new Interval('[0; 0]'); // throws exception (semicolon syntax not supported)
new Interval(']0, 2]'); // throws exception (reverse brackets not supported)
new Interval('[foo, bar]'); // throws exception (use numbers or INF)
new Interval('[0, 0)'); // throws exception (same endpoint, different boundary)
new Interval('[1, -1]'); // throws exception (upper- is less than lower-bound)
use Jstewmc\Interval;
$a = new Interval('(-INF, 0]');
$b = (new Interval())
->setLowerExclusive()
->setLower(-INF)
->setUpper(0)
->setUpperInclusive(true);
$a == $b; // returns true