PHP code example of remorhaz / int-rangesets

1. Go to this page and download the library: Download remorhaz/int-rangesets 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/ */

    

remorhaz / int-rangesets example snippets




use Remorhaz\IntRangeSets\Range;

// Contains values: 5, 6, 7, 8
$range1 = new Range(5, 8);

// Contains value 12
$range2 = new Range(12);



use Remorhaz\IntRangeSets\Range;

// Contains values: 5, 6, 7, 8
$range1 = new Range(5, 8);

// New range has first value replaced and contains values: 7, 8
$range2 = $range1->withStart(7);



use Remorhaz\IntRangeSets\Range;
use Remorhaz\IntRangeSets\RangeSet;

// Contains single range [3..5]
$rangeSet1 = RangeSet::create(new Range(3, 5));

// Added range [4..10] partially overlaps already existing one.
// Resulting range set contains single merged range [3..10].
$rangeSet2 = $rangeSet1->withRanges(new Range(4, 10));



use Remorhaz\IntRangeSets\Range;
use Remorhaz\IntRangeSets\RangeSet;

// Creates range with two ranges: [2..5] and [7..8].
$rangeSet1 = RangeSet::createUnsafe(new Range(2, 5), new Range(7, 8));