PHP code example of yunqing / interval

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

    

yunqing / interval example snippets


    // 构建区间
    $interval1 = new Interval();
    $interval1->setData(1, 8);
    // 设置开区间(默认创建闭区间)
    $interval1->setLeftOpen();
    $interval1->setRightOpen();
    // 获取集合数组
    $interval1->toArray();
  
    // 检查两个区间有没有交集
    $calculate = new IntervalCalculate();
    $checkIntersects = $calculate->checkIntersects($interval1, $interval2);
    // 获取两个区间的交集
    $getIntersects = $calculate->getIntersects($interval1, $interval2);
    // 获取两个区间的并集
    $union = $calculate->getUnion($interval1, $interval2);
    // 检查集合1是否包含集合2
    $calculate->checkContains($interval1, $interval2);