]> git.mxchange.org Git - mailer.git/blobdiff - inc/wrapper-functions.php
More rewrites/fixes:
[mailer.git] / inc / wrapper-functions.php
index 2adbd0968ceb67d5f4016c5990ae4be3649ffef5..354fe7cbe4743335007219fd6788d750b23f2518 100644 (file)
@@ -2802,6 +2802,40 @@ function parseFloat ($floatString){
        return floatval($floatString);
 }
 
+/**
+ * Searches a multi-dimensional array (as used in many places) for given
+ * key/value pair as taken from user comments from PHP documentation website.
+ *
+ * @param      $array          An array with one or more dimensions
+ * @param      $key            Key to look for
+ * @param      $valur          Value to look for
+ * @return     $results        Resulted array or empty array if $array is no array
+ * @author     sunelbe<at>gmail<dot>com
+ * @link       http://de.php.net/manual/en/function.array-search.php#110120
+ */
+function search_array ($array, $key, $value) {
+       // Init array result
+       $results = array();
+
+       // Is $array really an array?
+       if (is_array($array)) {
+               // Does key and value match?
+               if (isset($array[$key]) && $array[$key] == $value) {
+                       // Then add it as result
+                       $results[] = $array;
+               } // END - if
+
+               // Search for whole array
+               foreach ($array as $subArray) {
+                       // Search recursive and merge again
+                       $results = merge_array($results, search_array($subArray, $key, $value));
+               } // END - foreach
+       } // END - if
+
+       // Return resulting array
+       return $results;
+}
+
 // Generates a YES/NO option list from given default
 function generateYesNoOptions ($defaultValue = '') {
        // Generate it