JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed db_reposition(x, 0)
[wfpl.git] / misc.php
index 1737a86..8f46014 100644 (file)
--- a/misc.php
+++ b/misc.php
@@ -67,15 +67,12 @@ function exec_pipe($command, $stdin) {
 }
 
 
-
-
-
-
 function unix_newlines($str) {
        $str = str_replace("\r\n", "\n", $str);
        return str_replace("\r", "\n", $str);
 }
 
+
 # return current year (all 4 digits)
 function this_year() {
        return strftime('%Y');
@@ -105,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: columnize(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:
@@ -129,4 +146,8 @@ function ref(&$foo) {
        return new stupid_reference($foo);
 }
 
+function &last(&$array) {
+       if(count($array)) return $array[count($array) - 1];
+}
+
 ?>