Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test Snippet
// 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