gianarb/priority-array-merge

This package is abandoned and no longer maintained. No replacement package was suggested.

Merge array with different key priority

0.0.1 2015-01-11 16:50 UTC

This package is not auto-updated.

Last update: 2021-03-15 09:16:15 UTC


README

Build Status This lib help you to merge two array with key priority

<?php
$mergeManager = new PriorityArray();
$first = [
    'companyId' => 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]