Revision 0d90fcaf
Added by Jim Pingle about 15 years ago
etc/inc/util.inc | ||
---|---|---|
1332 | 1332 |
return false; |
1333 | 1333 |
} |
1334 | 1334 |
|
1335 |
/* |
|
1336 |
This function was borrowed from a comment on PHP.net at the following URL: |
|
1337 |
http://www.php.net/manual/en/function.array-merge-recursive.php#73843 |
|
1338 |
*/ |
|
1339 |
function array_merge_recursive_unique($array0, $array1) |
|
1340 |
{ |
|
1341 |
$arrays = func_get_args(); |
|
1342 |
$remains = $arrays; |
|
1343 |
|
|
1344 |
// We walk through each arrays and put value in the results (without |
|
1345 |
// considering previous value). |
|
1346 |
$result = array(); |
|
1347 |
|
|
1348 |
// loop available array |
|
1349 |
foreach($arrays as $array) { |
|
1350 |
|
|
1351 |
// The first remaining array is $array. We are processing it. So |
|
1352 |
// we remove it from remaing arrays. |
|
1353 |
array_shift($remains); |
|
1354 |
|
|
1355 |
// We don't care non array param, like array_merge since PHP 5.0. |
|
1356 |
if(is_array($array)) { |
|
1357 |
// Loop values |
|
1358 |
foreach($array as $key => $value) { |
|
1359 |
if(is_array($value)) { |
|
1360 |
// we gather all remaining arrays that have such key available |
|
1361 |
$args = array(); |
|
1362 |
foreach($remains as $remain) { |
|
1363 |
if(array_key_exists($key, $remain)) { |
|
1364 |
array_push($args, $remain[$key]); |
|
1365 |
} |
|
1366 |
} |
|
1367 |
|
|
1368 |
if(count($args) > 2) { |
|
1369 |
// put the recursion |
|
1370 |
$result[$key] = call_user_func_array(__FUNCTION__, $args); |
|
1371 |
} else { |
|
1372 |
foreach($value as $vkey => $vval) { |
|
1373 |
$result[$key][$vkey] = $vval; |
|
1374 |
} |
|
1375 |
} |
|
1376 |
} else { |
|
1377 |
// simply put the value |
|
1378 |
$result[$key] = $value; |
|
1379 |
} |
|
1380 |
} |
|
1381 |
} |
|
1382 |
} |
|
1383 |
return $result; |
|
1384 |
} |
|
1385 |
|
|
1335 | 1386 |
?> |
Also available in: Unified diff
Add array_merge_recursive_unique which was called in xmlrpc.php but did not yet exist. Fixes #645