JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed/rewrote display_messages(), added columnize
[wfpl.git] / misc.php
index b18abd4..1e9a2b7 100644 (file)
--- a/misc.php
+++ b/misc.php
@@ -102,6 +102,26 @@ function get_text_between($text, $start_text, $end_text) {
        return substr($text, 0, $end);
 }
 
+# Make it easy to insert an array into the template data structure so that each
+# element of the array gets its own row.
+#
+# passed this: columnate(array('a', 'b', 'c'), 'k');
+# it returns: array(array('k' => 'a'),
+#                   array('k' => 'b'),
+#                   array('k' => 'c'));
+# passed this: columnate(array(), 'k');
+# it returns: false
+function columnize($arr, $key = 'data') {
+       if(!$arr) {
+               return false;
+       }
+       $ret = array();
+       foreach($arr as $val) {
+               $ret[] = array($key => $val);
+       }
+       return $ret;
+}
+
 # php4 is broken, in that you cannot set a default value for a parameter that
 # is passed by reference. So, this is set up to use the following screwy
 # syntax: