2017 © Pedro Peláez
 

library array-class

Lightweight php package to work with arrays like in JavaScript or C#. Immutable-first. Collections-like

image

dragk/array-class

Lightweight php package to work with arrays like in JavaScript or C#. Immutable-first. Collections-like

  • Tuesday, June 5, 2018
  • by DragK
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ArrayClass - Array as object for PHP

Lightweight php package to work with arrays like (but fitted to PHP) in JavaScript or C#, so you can for example, chain methods. Immutable-first. Collections-like., (*1)

Project was built having in mind, that this library has to:, (*2)

  • be lightweight
  • be fast
  • be full tested
  • be strict typed for better security
  • have documentation
  • be like JavaScript/C# array object

Installation

Install the latest version with, (*3)

$ composer require dragk/array-class

Basic Usage

<?php

use DragK\ArrayClass;

$array = new ArrayClass([1, 3, 2, 4]);
$result = $array
            ->sort()
            ->reverse()
            ->map(function($value){
                return $value**2;
            })
            ->filter(function($value) {
                return $value > 8 ;
            })
            ->reduce(function($result, $value) {
                return $result + $value;
            });

var_dump($result); // int(25)
echo $array[1]; // 3

Remember, you can always use function () use ($var1, $varN) to pass to function more variables, for example.:, (*4)

$multiplier = 2;
$result = $array
            ->sort()
            ->reverse()
            ->map(function($value){
                return $value**2;
            })
            ->filter(function($value) {
                return $value > 8 ;
            })
            ->reduce(function($result, $value) use ($multiplier) {
                return ($result + $value) * $multiplier;
            });
echo $result; // 82

Documentation

About

Requirments

  • PHP 7.0 or above

Submitting suggestions

Bugs, feature request and code style/approach hints are tracked on GitHub, (*5)

License

ArrayClass is licensed under the MIT License - see the LICENSE file for details, (*6)

Acknowledgements

This library is inspired by JavaScript Array Object, although most concepts have been adjusted to fit to the PHP world., (*7)

The Versions

05/06 2018

dev-master

9999999-dev

Lightweight php package to work with arrays like in JavaScript or C#. Immutable-first. Collections-like

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

javascript array prototype chainable collections-like