Simple Loop Class

Related tags

Miscellaneous loops
Overview

Loops

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require isaeken/loops

Usage

Basic Usage

loop(5, function ($loop, $instance) {
    return $loop->odd;
}); // [false, true, false, true, false]

Get current loop

loop(2 ,function ($loop, $instance) {
    return [
        'iteration' => $loop->iteration,
        'index'     => $loop->index,
        'remaining' => $loop->remaining,
        'count'     => $loop->count,
        'first'     => $loop->first,
        'last'      => $loop->last,
        'odd'       => $loop->odd,
        'even'      => $loop->even,
    ];
});
// [
//  [
//    'iteration' => 0,
//    'index' => 0,
//    'remaining' => 1,
//    'count' => 2,
//    'first' => true,
//    'last' => false,
//    'odd' => false,
//    'even' => true,
//  ],
//  [
//    'iteration' => 1,
//    'index' => 1,
//    'remaining' => 0,
//    'count' => 2,
//    'first' => false,
//    'last' => true,
//    'odd' => true,
//    'even' => false,
//  ]
// ]

Break the loop

loop(3, function ($loop, $instance) {
    if ($loop->index > 1) {
        $instance->stop();
    }
    
    return $loop->index;
}); // [0, 1]

Loop random times

loop_random(function ($loop, $instance) {
    return $loop->index;
}); // executed random times.

$min = 5;
$max = 10;

loop_random(function ($loop, $instance) {
    return $loop->index;
}, $min, $max);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

Demonstration of OOP concepts and usage of Abstract class & Interfaces

Learn OOP Demonstration of OOP concepts and usage of Abstract class & Interfaces Usage clone this repo run composer install run php index.php Code str

Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

Music website developed as a final group project for our Webpage Development class.

double-drummer Music listening website developed as final group project for our Webpage Development course. All parts that disclosed any information r

Php-timer - Utility class for timing

phpunit/php-timer Utility class for timing things, factored out of PHPUnit into a stand-alone component. Installation You can add this library as a lo

Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀

Polonium Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀 to write dump articles about... Yeah I know, you should pr

This PHP class uploads files and manipulates images very easily

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP4, 5 and 7. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.

My solution use PHP with a class for easy setup

My solution use PHP with a class for easy setup. It accepts requests with the get method just passing the username and password as well as the ip and http port of the Proxmox server. Just needing a web server.

CRUD  Build a system to insert student name information, grade the class name, and edit and delete this information
CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

Comments
  • Improve assertions

    Improve assertions

    Changed log

    • Using the assertGreaterThanOrEqual to assert expected is greater than or equal to the result.
    • Using the assertLessThanOrEqual to assert is less than or equal to the result.
    opened by peter279k 0
Owner
İsa Eken
Creative developer passionate about PHP.
İsa Eken
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022
Simple class that implement a CAPTCHA for your PHP App.

simple-captcha Simple class that implement a CAPTCHA for your PHP App. Installation Use the package manager composer to install. composer require will

WILLIAM B. SAMPAIO 3 Nov 9, 2022
A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface.

smpl 9 Sep 1, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022
FuelPHP Framework - Class and Namespace alias library

Fuel Alias Library for lazy class aliasing. Install Via Composer $ composer require fuelphp/alias Usage Within FuelPHP class aliases are used to provi

fuelphp-storage 20 Feb 20, 2022
A class to help convert bytes into other units (kb, mb, etc).

A class to help convert bytes into other units (kb, mb, etc). This package can be used to convert int|float values from bytes to KB, MB and GB as well

Ryan Chandler 12 Mar 15, 2022
A small package to add computed properties to any PHP class. 🐘

Computed Properties This package provides a trait and attribute that can provide computed property support. Installation This package can be installed

Ryan Chandler 22 Mar 28, 2022
COP4331 Class Project 1 - "ConnectUs" virtual contact manager/Rolodex

ConnectUs COP4331 Class Project 1 - "ConnectUs" virtual contact manager/Rolodex Team Members Orion (Project Manager) Eric (Database) Rafael (API/Backe

Orion 3 Dec 9, 2022
Class for manage directly leds on raspberry pi in PHP

led_raspberry Class for manage directly leds on raspberry pi in PHP We can access GPIO ports directly with fwrite() for power on|off leds, without use

Rafael Martin Soto 8 Sep 15, 2021
A class for easy connection to the zarinpal port

Payment class with ZarinPal A class to simplify payment operations and confirm payment of ZarrinPal payment gateway service ( به فارسی بخوانید ) Insta

Mohammad Qasemi 7 Jul 15, 2022