Added helper functions for array manipulations.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 4 Nov 2008 12:26:10 +0000 (12:26 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 4 Nov 2008 12:26:10 +0000 (12:26 +0000)
includes/main.inc

index c148c4a2a319693d7a1c9bb89ccf1400df3981cd..f5bb4139c4d11c9eece88358bd075b305ed2f64d 100644 (file)
@@ -248,4 +248,22 @@ function js_compress($sJS)
        }
        return $sJS;
 }
+//-----------------------------------------------------------------------------
+//     Inserts $elements into $array at position $index.
+//     In contrast to array_splice() preserves keys of $elements array.
+//
+function array_insert(&$array, $index, $elements)
+{
+       if (!is_array($elements)) $elements = array($elements);
+
+       $head  = array_splice($array, 0, $index);
+       $array = array_merge($head, $elements, $array);
+
+}
+
+function array_remove(&$array, $index, $len=1)
+{
+       array_splice($array, $index, $len);
+}
+
 ?>
\ No newline at end of file