Skip to content

Instantly share code, notes, and snippets.

@hipsterjazzbo
Last active August 29, 2015 14:06
Show Gist options
  • Save hipsterjazzbo/2f938a4af346b5374d2f to your computer and use it in GitHub Desktop.
Save hipsterjazzbo/2f938a4af346b5374d2f to your computer and use it in GitHub Desktop.
<?php
public static function group_by(Array $objects, $group_by_property)
{
$grouped_objects = [];
foreach($objects as $object)
{
$property_value = $object->{$group_by_property};
$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