Created
January 17, 2012 15:32
-
-
Save mitchkramez/1627079 to your computer and use it in GitHub Desktop.
sort an array for output in columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* function: array_columns | |
* author: Brecht Cloetens | |
* params: $a = array() // original array | |
* $c = int() // number of columns | |
*/ | |
function array_columns(&$a, $c=2) | |
{ | |
$m = ceil(count($a)/$c); | |
$j = 0; | |
for($i=0; $i<$m; $i++) { | |
for($k=0; $k<$c; $k++) { | |
$key = $i+($m*$k); | |
settype($key,'integer'); | |
if(array_key_exists($key,$a)) { | |
$b[$j] = $a[$key]; | |
$j++; | |
} | |
} | |
} | |
$a = $b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment