diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2012-07-24 10:54:56 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2012-07-25 12:56:08 +0200 |
commit | 6b320a260434712d8c558bee431dd40af58883ad (patch) | |
tree | df4426d62bf91e4a79464f93a04658269deeb95e /lib/helper.php | |
parent | 42492338fc708a09ada3d4ef6f4cc8aa0c670ee3 (diff) | |
download | nextcloud-server-6b320a260434712d8c558bee431dd40af58883ad.tar.gz nextcloud-server-6b320a260434712d8c558bee431dd40af58883ad.zip |
provide recursiveArraySearch as Helper function and make available through API
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/helper.php b/lib/helper.php index f328c14ac77..666bc6badfc 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -360,7 +360,7 @@ class OC_Helper { }else{ $mimeType='application/octet-stream'; } - + if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ $info = @strtolower(finfo_file($finfo,$path)); if($info){ @@ -679,4 +679,30 @@ class OC_Helper { } return $subject; } + + /** + * @brief performs a search in a nested array + * @param haystack the array to be searched + * @param needle the search string + * @param $index optional, only search this key name + * @return the key of the matching field, otherwise false + * + * performs a search in a nested array + * + * taken from http://www.php.net/manual/en/function.array-search.php#97645 + */ + public static function recursiveArraySearch($haystack, $needle, $index = null) { + $aIt = new RecursiveArrayIterator($haystack); + $it = new RecursiveIteratorIterator($aIt); + + while($it->valid()) { + if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { + return $aIt->key(); + } + + $it->next(); + } + + return false; + } } |