2017 © Pedro Peláez
 

library array-util

Array utils - smart&fast array helpers

image

mufuphlex/array-util

Array utils - smart&fast array helpers

  • Sunday, May 15, 2016
  • by AlexMiroshnikov
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

mufuphlex array-util

Build Status Latest Stable Version License, (*1)

Array utils - smart&fast array helpers., (*2)

These helpers, among other things, provide a significantly improved (about 10-30 times faster) analogues of built-in PHP array functions, like unique() or intersect()., (*3)

unique() function

This is an improved (30 times faster!) implementation of standard array_unique() PHP function., (*4)

$arr = array(1,2,3,1,2,3);
$unique = \Mufuphlex\Util\ArrayUtil::unique($arr);
// array(1,2,3)

intersect() function

This is an improved (10 times faster!) implementation of standard array_intersect() PHP function., (*5)

$a = array(1,2,3);
$b = array(2,3,4);
$c = array(3,4,5);
$result = \Mufuphlex\Util\ArrayUtil::intersect($a, $b, $c);
// array(3)

cutBy*() functions

If you need to remove particular elements from an array by elements' keys, cutByWhitelist(array $array, array $map) and cutByBlacklist(array $array, array $map) can be very useful. cutByWhitelist() leaves in $array only elements which are listed in the $map and cutByBlacklist() - just in opposite - removes from $array elements listed in $map. Moreover, these functions can not only remove, but also modify $array's members via callbacks - smth like an extended version of standard PHP function array_walk()., (*6)

How to use it?, (*7)

Let's consider the following sample array:, (*8)

$array = [
    'result' => [
        'one' => [
            'param 1' => 1,
            'param 2' => 2,
            'param 3' => 3,
        ],
        'another' => [
            'param 1' => 4,
            'param 2' => 5,
            'param 3' => 6,
        ],
        'another one' => [
            'param 1' => 7,
            'param 2' => 8,
            'param 3' => 9,
        ]
    ],
    'errors' => [
        'form' => [
            'field 1' => [
                0 => 'error 1',
                1 => 'error 2'
            ],
            'field 2' => [
                0 => 'error 3',
                1 => 'error 4 '
            ]
        ],
        'logic' => [
            0 => 'logic error 1',
            1 => 'logic error 2'
        ]
    ],
    0 => [
        0 => 'item 1',
        1 => 'item 2'
    ],
    1 => [
        0 => 'item 3',
        1 => 'item 4'
    ],
    '123 - numeric containing' => [
        0 => 'item 5',
        1 => 'item 6'
    ],
    'not numeric containing' => [
        0 => 'item 5',
        1 => 'item 6'
    ],

];
  1. Leave/remove elements in/from `array.result*` with keys containing only `one` or only `another`:
    $map = [
        'result' => [
            '/^(?:one|another)$/' => true
        ]
    ];
    
  2. Leave/remove only elements in/from `array.errors.logic`:
    $map = [
        'errors' => [
            'logic' => true
        ]
    ];
    
  3. Leave/remove only elements with key `0` from `array.errors.form.field *.*`:
    $map = [
        'errors' => [
            'form' => [
                'field \d+' => [
                    0 => true
                ]
            ]
        ]
    ];
    
  4. Leave/remove elements in/from `array.result.*` with keys `param 3` and/or modify these elements' values by adding 5:
    $map = [
        'result' => [
            '/.+/' => [
                'param 3' => function($arg){ return $arg+=5; }
            ]
        ]
    ];
    

The Versions

15/05 2016

dev-master

9999999-dev

Array utils - smart&fast array helpers

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.9

 

The Development Requires

by Avatar AlexMiroshnikov

array array walk array util array map array cut array intersect array unique smart intersect smart unique fast intersect fast unique

14/11 2015

0.1.2

0.1.2.0

Array utils - smart&fast array helpers

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.9

 

The Development Requires

by Avatar AlexMiroshnikov

array array walk array util array map array cut array intersect array unique smart intersect smart unique fast intersect fast unique

14/11 2015

0.1.1

0.1.1.0

Array utils - smart&fast array helpers

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.9

 

The Development Requires

by Avatar AlexMiroshnikov

array array walk array util array map array cut array intersect array unique smart intersect smart unique fast intersect fast unique

14/11 2015

dev-develop

dev-develop

Array utils - smart&fast array helpers

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.9

 

The Development Requires

by Avatar AlexMiroshnikov

array array walk array util array map array cut array intersect array unique smart intersect smart unique fast intersect fast unique

14/11 2015

0.1

0.1.0.0

Array utils - smart&fast array helpers

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.9

 

The Development Requires

by Avatar AlexMiroshnikov

array array walk array util array map array cut array intersect array unique smart intersect smart unique fast intersect fast unique