srph / map-range
A more efficient foreach-range
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/srph/map-range
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2025-10-15 14:55:33 UTC
README
composer require srph/map-range
A more efficient foreach
-range
.
Usage
SRPH\MapRange\map_range(function($index) { // do something }, $from, $to);
For PHP >=v5.6, you can use the use function (aka import function) syntax:
use function SRPH\MapRange\map_range; map_range(function($index) { // do something }, $from, $to);
Note that it iterates while $from <= $to
.
Why
Because some developers prefer this
foreach(range(0, 10) as $i) { // .. }
Over this:
for ( $i = 0; $i < 10; $i++ ) { // }
In which the first example generates a buffer array first (which is terrible for performance).