PHP code example of gianarb / priority-array-merge

1. Go to this page and download the library: Download gianarb/priority-array-merge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gianarb / priority-array-merge example snippets



$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"]