Download the PHP package mufuphlex/array-util without Composer
On this page you can find all versions of the php package mufuphlex/array-util. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mufuphlex/array-util
More information about mufuphlex/array-util
Files in mufuphlex/array-util
Package array-util
Short Description Array utils - smart&fast array helpers
License MIT
Informations about the package array-util
mufuphlex array-util
Array utils - smart&fast array helpers.
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().
unique() function
This is an improved (30 times faster!) implementation of standard array_unique() PHP function.
intersect() function
This is an improved (10 times faster!) implementation of standard array_intersect() PHP function.
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().
How to use it?
Let's consider the following sample array:
$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'
],
];
- Leave/remove elements in/from `array.result*` with keys containing only `one` or only `another`:
$map = [ 'result' => [ '/^(?:one|another)$/' => true ] ]; - Leave/remove only elements in/from `array.errors.logic`:
$map = [ 'errors' => [ 'logic' => true ] ]; - Leave/remove only elements with key `0` from `array.errors.form.field *.*`:
$map = [ 'errors' => [ 'form' => [ 'field \d+' => [ 0 => true ] ] ] ]; - 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; } ] ] ];