X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fcurrent_user.inc;h=c4d94539df5797c01dad0cfd64d9f4fc0c754242;hb=bd3023c1b5e64429043358a691b3aae20eb54c09;hp=408addb427866289ae329ffa8de4ccdcd2396849;hpb=f7b0f0130571e3473baead5cffe25666170fe70f;p=fa-stable.git diff --git a/includes/current_user.inc b/includes/current_user.inc index 408addb4..c4d94539 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -460,7 +460,10 @@ function array_append(&$array, $elements) $array[$key] = $el; } } - +// +// Search $needle in $haystack or in $haystack[][$valuekey] +// returns $needle found or null. +// function array_search_value($needle, $haystack, $valuekey=null) { foreach($haystack as $key => $value) { @@ -471,15 +474,29 @@ function array_search_value($needle, $haystack, $valuekey=null) } return null; } - +// +// Search $needle in $haystack or in $haystack[][$valuekey] +// returns array of keys of $haystack elements found +// +function array_search_keys($needle, $haystack, $valuekey=null) +{ + $keys = array(); + if($haystack) + foreach($haystack as $key => $value) { + $val = isset($valuekey) ? $value[$valuekey] : $value; + if ($needle == $val){ + $keys[] = $key; + } + } + return $keys; +} +// +// Find first (single) $needle in $haystack or in $haystack[][$valuekey] +// returns $haystack element found or 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; + $keys = array_search_keys($needle, $haystack, $valuekey); + return @$keys[0]; } ?> \ No newline at end of file