All pastes #640823 Raw Edit

Someone

public text v1 · immutable
#640823 ·published 2007-07-31 18:23 UTC
rendered paste body
// FUNC: split_cols($arr, $cols, $val)
// $arr = array you want to split into columns
// $cols = number of columns (overflow will add one more)
// $val = string to put in each column. {val} outputs each array value
// ex: split_cols($years, 5, '<a href="/movies/{val}/" title="movies in year {val}">{val}</a>');
function split_cols($arr, $cols, $val)
{
		$tot = count($arr);
		for($i=0;$i<=$tot;$i++)
			$arr2[$i+1] = $arr[$i];
		$arr = $arr2;
		$arr[0] = '-';
		$k = 0;
		for($i=0;$i<=$cols;$i++)
		{
			$per_col = ($tot / $cols) - 1;
			echo '<td>';
			for($j=$k+1;$j<=$k+$per_col;$j++)
				echo str_replace('{val}', $arr[$j], $val) . '<br />';
			echo '</td>';
			$k += $per_col;
		}
}

<table cellpadding="20px" style="line-height:1.3em;text-align:left;">
	<tr>
		<?php
		split_cols($years, 5, '<a href="/movies/{val}/" title="movies in year {val}">{val}</a>');
		?>
	</tr>
</table>