X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=misc.php;h=1e9a2b7c84a135d96cd8075bec092b4a13ec1229;hb=19290886b2b738f1cc43f2d7bdea74bf05603b17;hp=b18abd43b9f62aeeebf3cac3a7408705aa3af1c4;hpb=f22aa9e82ee43e5d390bcb5ab076b24a93e8fda2;p=wfpl.git diff --git a/misc.php b/misc.php index b18abd4..1e9a2b7 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: 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: