Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utils.php
Show First 20 Lines • Show All 729 Lines • ▼ Show 20 Lines | |||||
function array_mergev(array $arrayv) { | function array_mergev(array $arrayv) { | ||||
if (!$arrayv) { | if (!$arrayv) { | ||||
return array(); | return array(); | ||||
} | } | ||||
return call_user_func_array('array_merge', $arrayv); | return call_user_func_array('array_merge', $arrayv); | ||||
} | } | ||||
/** | |||||
* Merges two arrays recursively and "binary safe" (integer keys are overridden | |||||
* as well), overruling similar values in the original array with the values of | |||||
* the overrule array. In case of identical keys, ie. keeping the values of the | |||||
* overrule array. | |||||
* | |||||
* The differences to the existing PHP function array_merge_recursive() is that | |||||
* elements or the original array get overwritten if the same key is present in | |||||
* the overrule array. | |||||
* | |||||
* @param array Array with the original values | |||||
* @param array Array with the values that should overrule the values | |||||
* from the original array | |||||
* @return array the overruled array | |||||
*/ | |||||
function array_merge_recursive_overrule(array $original, array $overrule) { | |||||
foreach (array_keys($overrule) as $key) { | |||||
if (isset( | |||||
$original[$key]) && | |||||
is_array($original[$key]) && | |||||
is_array($overrule[$key])) { | |||||
$original[$key] = array_merge_recursive_overrule( | |||||
$original[$key], $overrule[$key]); | |||||
} else { | |||||
$original[$key] = $overrule[$key]; | |||||
} | |||||
} | |||||
return $original; | |||||
} | |||||
/** | /** | ||||
* Split a corpus of text into lines. This function splits on "\n", "\r\n", or | * Split a corpus of text into lines. This function splits on "\n", "\r\n", or | ||||
* a mixture of any of them. | * a mixture of any of them. | ||||
* | * | ||||
* NOTE: This function does not treat "\r" on its own as a newline because none | * NOTE: This function does not treat "\r" on its own as a newline because none | ||||
* of SVN, Git or Mercurial do on any OS. | * of SVN, Git or Mercurial do on any OS. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |