2017 © Pedro Peláez
 

library array-walker

Better implementation foreach operator with nested array compability.

image

andydune/array-walker

Better implementation foreach operator with nested array compability.

  • Wednesday, June 20, 2018
  • by AndyDune
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ArrayWalker

Build Status Software License Packagist Version Total Downloads, (*1)

Better implementation foreach operator with nested array compability., (*2)

Installation

Installation using composer:, (*3)

composer require andydune/array-walker

Or if composer was not installed globally:, (*4)

php composer.phar require andydune/array-walker

Or edit your composer.json:, (*5)

"require" : {
     "andydune/array-walker": "^1"
}

And execute command:, (*6)

php composer.phar update

Example

use AndyDune\ArrayWalker\ArrayWalker;
use AndyDune\ArrayWalker\ItemContainer;

// Source array
$array = [
    'one' => 1,
    'two' => 2,
    'three' => 3,
];

$arrayWalker = new ArrayWalker($array);
// Change values
$arrayWalker->addFunction(function (ItemContainer $item) {
    $item->setValue($item->getValue() + 10);
});
$result = $arrayWalker->apply();
$result = [
    'one' => 11,
    'two' => 12,
    'three' => 13,
];

$arrayWalker = new ArrayWalker($array);
// Change keys
$arrayWalker->addFunction(function (ItemContainer $item) {
   $item->setKey(strtoupper($item->getKey()));
});
$result = $arrayWalker->apply();
$result = [
    'ONE' => 1,
    'TWO' => 2,
    'THREE' => 3,
];

$arrayWalker = new ArrayWalker($array);
// Delete value 
$arrayWalker = new ArrayWalker($array);
$arrayWalker->addFunction(function (ItemContainer $item) {
    $item->setValue($item->getValue() + 10);
    if ($item->getKey() == 'one') {
        $item->delete();
    }
});
$result = $arrayWalker->apply();

$result = [
    'two' => 12,
    'three' => 13,
];

The Versions

20/06 2018

dev-master

9999999-dev https://github.com/AndyDune/ArrayWalker

Better implementation foreach operator with nested array compability.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

php array

18/05 2018

v1.0.0

1.0.0.0 https://github.com/AndyDune/ArrayWalker

Better implementation foreach operator with nested array compability.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

php array