PHPackages                             clouding/range - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. clouding/range

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

clouding/range
==============

A simple library for range object.

v1.1.1(7y ago)33MITPHPPHP ^7.1.3

Since Jan 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/cloudingcity/range)[ Packagist](https://packagist.org/packages/clouding/range)[ RSS](/packages/clouding-range/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Range
=====

[](#range)

[![](https://camo.githubusercontent.com/53b6a84c2576bd1ad61f8ce7a6227ecf3fd355fb8a1f661943c0990f7214ce70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636c6f7564696e672f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/clouding/range)[![](https://camo.githubusercontent.com/ce4576b45939c91311d6978f9162ac1ad79300ce371e3ce72412476f0a2801f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c6f7564696e672f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/clouding/range)[![](https://camo.githubusercontent.com/a844765dfa594b1b006b00def65548fc80d1e169a33cfa78c5e5c7a71a0b3fc3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f636c6f7564696e67636974792f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/cloudingcity/range)[![](https://camo.githubusercontent.com/83ab45854ebef48f6b193200151ca6960a0388c7caa8f54d5242b99a3159e347/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f636c6f7564696e67636974792f6b6174612e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/cloudingcity/range)[![PHPStan](https://camo.githubusercontent.com/31ad7b4f47dbce7e8cf0f7ba16b958bffbf22a1b2fabd2e901e37cd2302be626/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c61742d737175617265)](https://github.com/phpstan/phpstan)

A simple library for **Range** object.

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
    - [Create](#create)
    - [Getters](#getters)
    - [Comparison](#comparison)
    - [Conversion](#conversion)
    - [Functions](#functions)

Installation
------------

[](#installation)

```
composer require clouding/range

```

Usage
-----

[](#usage)

### Create

[](#create)

Create a new instance:

```
use Clouding\Range\Range;

$range = new Range(1, 10);
```

Create a instance from string:

```
$range = Range::parse('1..10');
```

### Getters

[](#getters)

Get start or end:

```
echo $range->start; // 1

echo $range->end;   // 10
```

### Comparison

[](#comparison)

Determine contains integer or not:

```
$range = new Range(1, 10);

var_dump($range->contains(5)); // bool(true)
```

Determine two range instances is equals or not:

```
$range = new Range(1, 10);
$rangeFoo = new Range(1, 10);

var_dump($range->equals($rangeFoo)); // bool(true)
```

Determine two range instances is intersect or not:

```
$range = new Range(1, 10);
$rangeBar = new Range(5, 10);

var_dump($range->intersect($rangeBar)); // bool(true)
```

### Conversion

[](#conversion)

Get the instance as a string:

```
$range = Range::parse('-5..5');

echo $range;            // -5..5
echo $range->toString() // -5..5
```

Get the instance as an array:

```
$range = new Range(1, 5);

var_dump($range->toArray());  // [1, 2, 3, 4, 5]

// with gap 2
var_dump($range->toArray(2)); // [1, 3, 5]
```

Formatting string:

```
echo $range->format(':start ~ :end');       // 1 ~ 10

echo $range->format('From :start to :end'); // From 1 to 10
```

### Functions

[](#functions)

Execute a callback over each integer of range:

```
$range = new Range(1, 5);

$range->each(function ($int) {
    echo $int, ', ';
});
// 1, 2, 3, 4, 5,

$range->each(function ($int) {
    if ($int >= 3) {
        return false;
    }
    echo $int . ', ';
});
// 1, 2,

// with gap 2
$range->each(function($int) {
    echo $int . ', ';
}, 2);
// 1, 3, 5,
```

Get random integer of the range:

```
$range = new Range(1, 10);

echo $range->random();       // 3

var_dump($range->random(3)); // [3, 2, 9]
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

2681d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea2b60c4800aa41ed8a6817f3cd4301d75770cfeda9df623ef48ca5ab39dc061?d=identicon)[cloudingcity](/maintainers/cloudingcity)

---

Top Contributors

[![cloudingcity](https://avatars.githubusercontent.com/u/11569651?v=4)](https://github.com/cloudingcity "cloudingcity (34 commits)")

---

Tags

rangelibraryrange

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/clouding-range/health.svg)

```
[![Health](https://phpackages.com/badges/clouding-range/health.svg)](https://phpackages.com/packages/clouding-range)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)[payum/iso4217

ISO 4217 PHP Library

16312.1M5](/packages/payum-iso4217)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
