/** * Splits categories into two equal parts * * @return array */ static function splitInHalf() { $categoryWeight = 4; $all = self::visible()->get(); $totalVisibleSkills = Skill::visible()->count() + count($all) * $categoryWeight; $splitted = [[], []]; $currentSkillsCount = 0; $currentArray =& $splitted[0]; foreach ($all as $category) { $skills = $category->visibleSkills()->count() + $categoryWeight; array_push($currentArray, $category); $currentSkillsCount += $skills; if ($currentSkillsCount > $totalVisibleSkills / 2 && empty($splitted[1])) { $currentArray =& $splitted[1]; } } return $splitted; }