enzyme/loopy

A loop library for PHP.

v1.0.0 2016-04-03 07:54 UTC

This package is not auto-updated.

Last update: 2024-12-07 19:44:31 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

A loop library for PHP.

Installation

Run the following command inside of your project directory.

composer require enzyme/loopy

Usage

Simple

A simple loop over an array.

use Enzyme\Loopy\Each;

$array = [1, 2, 3];

Each::shallow()->begin($array, function($bag) {
    echo $bag->value() . ', ';
});

The above will output 1, 2, 3,

Deep

A deep loop over a multidimensional array.

use Enzyme\Loopy\Each;

$array = [1, 2, 3, 4 => [4, 5, 6]];

Each::deep()->begin($array, function($bag) {
    echo $bag->value() . ', ';
});

The above will output 1, 2, 3, 4, 5, 6,

Filtered

A loop over a filtered array.

use Enzyme\Loopy\Each;
use Enzyme\Loopy\Filters\SkipNulls;

$array = [1, 2, null, 4, 5];

Each::deep(new SkipNulls)->begin($array, function($bag) {
    echo $bag->value() . ', ';
});

The above will output 1, 2, 4, 5,

Bags

The $bag object passed to the callback function generally contains the follow information.

Filters