Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public static function group_by(Array $objects, $group_by_property)
$grouped_objects = [];
foreach($objects as $object)
$property_value = $object->{$group_by_property};
if (! isset($grouped_objects[$property_value]))
$grouped_objects[$property_value] = [];
$grouped_objects[$property_value][] = $object;
return $grouped_objects;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.