Created
May 7, 2015 14:14
-
-
Save Norcoen/1e3db5c28e9f3e354aa6 to your computer and use it in GitHub Desktop.
Test Snippet
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
// Länder sollen Vertikal von A-Z anstatt Horizontal sortiert werden | |
function sort_market_verticaly($markets, $marketColumns = 5) { | |
$countMarkets = count($markets); | |
$numMarketsPerBlock = intval($countMarkets / $marketColumns); | |
$leftOver = $countMarkets % $marketColumns; | |
$newSortMarkets = array(); | |
for ($i = 0, $marketCount = 0; $i < $marketColumns && $marketCount < $countMarkets; $i++) { | |
for ($j = 0; $j < $numMarketsPerBlock; $j++) { | |
$newSortMarkets[$i][] = $markets[$marketCount]; | |
$marketCount++; | |
} | |
if ($leftOver > 0) { | |
$newSortMarkets[$i][] = $markets[$marketCount]; | |
$marketCount++; | |
$leftOver--; | |
} | |
} | |
$markets_new = array(); | |
for ($i = 0; $i < count($newSortMarkets[0]); $i++) { | |
for ($j = 0; $j < $marketColumns; $j++) { | |
if (isset($newSortMarkets[$j][$i])) { | |
$markets_new[] = $newSortMarkets[$j][$i]; | |
} | |
else { | |
break; | |
} | |
} | |
} | |
return $markets_new; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment