public function groupBy($array, $columns)
    {
        // ensure $columns parameter is array
        $columns = (array) $columns;

        // get first group-by column
        $col = array_shift($columns);

        $result = array();
        foreach ($array as $row) {
            $key = (string) is_object($row) ? $row->$col : $row[$col];
            if (!isset($result[$key])) {
                $result[$key] = array();
            }

            $result[$key][] = $row;
        }

        // do subsequent group by calls
        if (count($columns)) {
            foreach (array_keys($result) as $key) {
                $result[$key] = $this->groupBy($result[$key], $columns);
            }
        }

        return $result;
    }