2017 © Pedro Peláez
 

library array-walker

ArrayWalker, OOP wrapper for array_walk() and array_map()

image

noi/array-walker

ArrayWalker, OOP wrapper for array_walk() and array_map()

  • Thursday, September 19, 2013
  • by noisan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ArrayWalker

An OOP wrapper for the built-in array_walk() and array_map()., (*1)

Installation

Using Composer, just $ composer require noi/array-walker package or:, (*2)

{
    "require": {
        "noi/array-walker": "dev-master"
    }
}

Usage

Example 1:, (*3)

<?php
$names = array('*APPLE*', '*ORANGE*', '*LEMON*');

$walker = new \Noi\Util\ArrayWalker($names);
$result = $walker->trim('*')->strtolower()->ucfirst();

assert($result->getArrayCopy() === array('Apple', 'Orange', 'Lemon'));
assert((array) $result === array('Apple', 'Orange', 'Lemon'));

The following code returns the same result as the above:, (*4)

// ...
$result = $walker->map(function ($name) {
    return ucfirst(strtolower(trim($name, '*')));
});

Example 2:, (*5)

<?php
$dom = new \DOMDocument();
$dom->loadXML('<users><user>Alice</user><user>Bob</user></users>');
$users = $dom->getElementsByTagName('user');

$walker = new \Noi\Util\ArrayWalker($users);
$walker->setAttribute('type', 'engineer');

assert(trim($dom->saveHtml()) ==
    '<users><user type="engineer">Alice</user><user type="engineer">Bob</user></users>');

The following code returns the same result as the above:, (*6)

// ...
$walker->walk(function ($node) {
    $node->setAttribute('type', 'engineer');
});

License

ArrayWalker is licensed under the MIT License - see the LICENSE file for details., (*7)

The Versions

19/09 2013

dev-master

9999999-dev

ArrayWalker, OOP wrapper for array_walk() and array_map()

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Akihiro Yamanoi

array wrapper iterator oop walker