1. Go to this page and download the library: Download ciloe/ranges 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/ */
ciloe / ranges example snippets
use Ciloe\Ranges\IntRange;
// Create a range [1, 10]
$range = new IntRange(1, 10, '[', ']');
// Check if a value is in the range
$range->contains(5); // true
// Generate a series of values in the range
$range->generateSeries(); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
use Ciloe\Ranges\BigIntRange;
// Create a range with values beyond PHP_INT_MAX
// PHP_INT_MAX on 64-bit systems is 9223372036854775807
$range = new BigIntRange('9223372036854775808', '9223372036854775818', '[', ']');
// Check if a value is in the range
$range->contains('9223372036854775810'); // true
// Generate a series of values in the range
$series = $range->generateSeries(); // ['9223372036854775808', '9223372036854775809', ...]
// Perform operations with very large integers
$shifted = $range->shift('1000000000000000000');
// $shifted now represents [10223372036854775808, 10223372036854775818]
$scaled = $range->scale('2');
// $scaled now represents [18446744073709551616, 18446744073709551636]
use Ciloe\Ranges\DateRange;
use DateTimeImmutable;
use DateInterval;
// Create a date range from 2023-01-01 to 2023-01-10
$range = new DateRange(
new DateTimeImmutable('2023-01-01'),
new DateTimeImmutable('2023-01-10'),
'[',
']'
);
// Check if a date is in the range
$range->contains(new DateTimeImmutable('2023-01-05')); // true
// Generate a series of dates in the range (with default 1-day step)
$dates = $range->generateSeries(); // Array of DateTimeImmutable objects from 2023-01-01 to 2023-01-10
// Create a range with weekly steps
$weeklyRange = new DateRange(
new DateTimeImmutable('2023-01-01'),
new DateTimeImmutable('2023-01-31'),
'[',
']',
new DateInterval('P1W')
);
$weeklyDates = $weeklyRange->generateSeries(); // [2023-01-01, 2023-01-08, 2023-01-15, 2023-01-22, 2023-01-29]
// Shift a date range
$shifted = $range->shift(new DateInterval('P1M')); // [2023-02-01, 2023-02-10]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.