forked from maciejczyzewski/bottomline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign.php
56 lines (54 loc) · 1.11 KB
/
assign.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace collections;
/**
* Combines and merge collections provided with each others.
*
* If the collections have common keys, then the last passed keys override the
* previous. If numerical indexes are passed, then last passed indexes override
* the previous.
*
* For a recursive merge, see `__::merge()`.
*
* **Usage**
*
* ```php
* __::assign(
* [
* 'color' => [
* 'favorite' => 'red',
* 5
* ],
* 3
* ],
* [
* 10,
* 'color' => [
* 'favorite' => 'green',
* 'blue'
* ]
* ]
* );
* ```
*
* **Result**
*
* ```
* [
* 'color' => ['favorite' => 'green', 'blue'],
* 10
* ]
* ```
*
* @param array|object ...$_ Collections to assign.
*
* @return array|object Assigned collection.
*/
function assign($_)
{
return \__::reduceRight(func_get_args(), function ($source, $result) {
\__::doForEach($source, function ($sourceValue, $key) use (&$result) {
$result = \__::set($result, $key, $sourceValue);
});
return $result;
}, []);
}