From 6e7684f82b40489bd1d7d8236439a147e723f8ba Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 4 Nov 2008 12:26:10 +0000 Subject: [PATCH] Added helper functions for array manipulations. --- includes/main.inc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/main.inc b/includes/main.inc index c148c4a2..f5bb4139 100644 --- a/includes/main.inc +++ b/includes/main.inc @@ -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 -- 2.30.2