X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=misc.php;h=8f460140a1692db6643cca268d8c1eb223a9d2b5;hb=6e641341473c1e4ddb306bdf44730bc7d307f975;hp=857f6db9e8c5b413e24ccb87f2a5bae54b594564;hpb=28ea182162da1c22d16f93bc2cb5619c14e222a7;p=wfpl.git diff --git a/misc.php b/misc.php index 857f6db..8f46014 100644 --- 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: 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: @@ -126,4 +146,8 @@ function ref(&$foo) { return new stupid_reference($foo); } +function &last(&$array) { + if(count($array)) return $array[count($array) - 1]; +} + ?>