update_user_prefs($this->user, $prefs);
}
- $this->prefs = new user_prefs($prefs);
+ $this->prefs = new user_prefs(get_user($this->user));
}
}
$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) {
}
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