Skip to content

Instantly share code, notes, and snippets.

@Norcoen
Created May 7, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Norcoen/1e3db5c28e9f3e354aa6 to your computer and use it in GitHub Desktop.
Save Norcoen/1e3db5c28e9f3e354aa6 to your computer and use it in GitHub Desktop.
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