Polyfill added for array_replace_recursive

This is natively available in PHP 5.3+
This commit is contained in:
Matt Pass
2014-10-24 09:23:52 +01:00
parent 084269bf35
commit 9ea459787e
2 changed files with 31 additions and 1 deletions

View File

@@ -128,4 +128,34 @@ function toUTF8noBOM($string,$message) {
}
return $string;
}
// Polyfill for array_replace_recursive, which is in PHP 5.3+
if (!function_exists('array_replace_recursive')) {
function array_replace_recursive($base, $replacements) {
foreach (array_slice(func_get_args(), 1) as $replacements) {
$bref_stack = array(&$base);
$head_stack = array($replacements);
do {
end($bref_stack);
$bref = &$bref_stack[key($bref_stack)];
$head = array_pop($head_stack);
unset($bref_stack[key($bref_stack)]);
foreach (array_keys($head) as $key) {
if (isset($key, $bref) && is_array($bref[$key]) && is_array($head[$key])) {
$bref_stack[] = &$bref[$key];
$head_stack[] = $head[$key];
} else {
$bref[$key] = $head[$key];
}
}
} while(count($head_stack));
}
return $base;
}
}
?>

View File

@@ -45,7 +45,7 @@ include(dirname(__FILE__)."/../lang/english.php");
$englishText = $text;
// Load chosen language ontop to replace English
include(dirname(__FILE__)."/../lang/english.php");
$text = array_replace_recursive ($englishText, $text);
$text = array_replace_recursive($englishText, $text);
$_SESSION['text'] = $text;
// Login not required or we're in demo mode and have password set in our settings, log us straight in