<?php /** */ function list_group($list, $collation = null) { if ($collation == null) { $collation = (function ($x, $y) {return ($x == $y);}); } $groups = []; foreach ($list as $element) { $found = false; $group = null; foreach ($groups as $group_) { if ($collation($group_[0], $element)) { $group = $group_; $found = true; break; } } if (! $found) { $group = []; } array_push($group, $element); if (! $found) { array_push($groups, $group); } } return $groups; } /** */ function list_clean($list, $collation = null) { return ( array_map ( function ($group) {return $group[0];}, list_group($list, $collation) ) ); } ?>