https://github.com/gianarb/priority-array-merge
Merge array with priority
https://github.com/gianarb/priority-array-merge
Last synced: 9 months ago
JSON representation
Merge array with priority
- Host: GitHub
- URL: https://github.com/gianarb/priority-array-merge
- Owner: gianarb
- License: mit
- Created: 2015-01-11T15:54:27.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-12T20:47:06.000Z (over 11 years ago)
- Last Synced: 2025-02-01T21:43:42.012Z (over 1 year ago)
- Language: PHP
- Size: 142 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Priority merge array
[](https://travis-ci.org/gianarb/priority-array-merge)
This lib help you to merge two array with key priority
```php
0,
'companyCode' => 1,
'companyName' => 1,
];
$second = [
'companyId' => 1,
'companyCode' => 0,
'companyName' => 0,
];
$mergeManager->setMapPriority($first, $second);
$arr1 = [
'companyId' => '012',
'companyCode' => 'B353sf',
'companyName' => 'Fox',
];
$arr2 = [
'companyId' => '024',
'companyCode' => 'A352gh',
'companyName' => 'BBC',
];
var_dump($mergeManager->merge($arr1, $arr2));
// output ["companyId"=>"024", "companyCode": "B353sf", "companyName": "Fox"]
```
## Benchamarks
```
GianArb\Benchmarks\Util\ArrayMergeEvent
Method Name Iterations Average Time Ops/second
------------------------------- ------------ -------------- -------------
mergeTwoArrayWithNativeFunction: [1,000 ] [0.0000039789677] [251,321.46923]
mergeTwoArrayWithPriority : [1,000 ] [0.0000096676350] [103,437.91462]
```