enhance css

This commit is contained in:
Ludovic CANDELLIER
2023-02-05 21:40:05 +01:00
parent 0123885e03
commit 32291dc44a
21 changed files with 553 additions and 121 deletions

View File

@@ -16,4 +16,50 @@ class Arrays
unset($array[$oldkey]);
return $array;
}
public static function slotify($array, $length)
{
// Create a placeholder array and calculate the number of items
// needed per slot (think card dealing LtoR).
for ($slots = array_fill(0, $length, 0), $count = count($array), $i = 0; $i < $count; $slots[$i % $length]++, $i++);
// Now just take slices of the original array
// depending on the calculated slot number and place in our slots
foreach ($slots as $k => $n) {
$slots[$k] = array_splice($array, 0, $n);
}
return $slots;
}
public static function alternate_chunk($array, $parts)
{
$t = 0;
$result = array();
$max = ceil(count($array) / $parts);
foreach (array_chunk($array, $max) as $v) {
if ($t < $parts) {
$result[] = $v;
} else {
foreach ($v as $d) {
$result[] = array($d);
}
}
$t += count($v);
}
return $result;
}
public static function fill_chunk($array, $parts)
{
$t = 0;
$result = array_fill(0, $parts - 1, array());
$max = ceil(count($array) / $parts);
foreach ($array as $v) {
count($result[$t]) >= $max and $t ++;
$result[$t][] = $v;
}
return $result;
}
}