From: Janusz Dobrowolski Date: Sun, 29 Nov 2009 14:36:20 +0000 (+0000) Subject: Array helpers moved from main.,inc. Added array_search_value and array_search_key X-Git-Tag: 2.3-final~1112 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=2a49105ee2573b6167425382888f0cf5ae0e5e3a;p=fa-stable.git Array helpers moved from main.,inc. Added array_search_value and array_search_key --- diff --git a/includes/current_user.inc b/includes/current_user.inc index 99d31477..29705106 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -424,4 +424,59 @@ function session_timeout() $tout = @get_company_pref('login_tout'); // mask warning for db ver. 2.2 return $tout ? $tout : ini_get('session.gc_maxlifetime'); } + +//----------------------------------------------------------------------------- +// Inserts $elements into $array at position $index. +// $elements is list of any objects +// +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); +} + +function array_substitute(&$array, $index, $len, $elements) +{ + array_splice($array, $index, $len); + array_insert($array, $index, $elements); +} + +function array_append(&$array, $elements) +{ + foreach($elements as $key => $el) { + if(is_int($key)) + $array[] = $el; + else + $array[$key] = $el; + } +} + +function array_search_value($needle, $haystack, $valuekey=null) +{ + foreach($haystack as $key => $value) { + $val = isset($valuekey) ? $value[$valuekey] : $value; + if ($needle == $val){ + return $value; + } + } + return null; +} + +function array_search_key($needle, $haystack, $valuekey=null) +{ + foreach($haystack as $key => $value) { + $val = isset($valuekey) ? $value[$valuekey] : $value; + if ($needle == $val){ + return $key; + } + } + return null; +} ?> \ No newline at end of file