Branch merge of preferences work branch. Includes fixes for several bugs. WARNING...
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 3872071..c5a6f29 100644 (file)
@@ -3096,3 +3096,25 @@ function wfStripIllegalFilenameChars( $name ) {
        $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name );
        return $name;
 }
+
+/**
+  * Insert array into another array after the specified *KEY*
+  * @param array $array        The array.
+  * @param array $insert       The array to insert.
+  * @param mixed $after        The key to insert after
+  */
+function wfArrayInsertAfter( $array, $insert, $after ) {
+       // Find the offset of the element to insert after.
+       $keys = array_keys($array);
+       $offsetByKey = array_flip( $keys );
+       
+       $offset = $offsetByKey[$after];
+       
+       // Insert at the specified offset
+       $before = array_slice( $array, 0, $offset + 1, true );
+       $after = array_slice( $array, $offset + 1, count($array)-$offset, true );
+       
+       $output = $before + $insert + $after;
+       
+       return $output;
+}