public static function assignByKey($array, $key, $group = false)
    {

        if (empty($array)) return $array;

        $res = array();
        foreach ($array as $subthing) {
            $idx = null;
            if (is_object($subthing) && property_exists($subthing, $key)) {
                $idx = $subthing->$key;
            } elseif (is_array($subthing) && isset($subthing[$key])) {
                $idx = $subthing[$key];
            }
            if ($idx !== null) {
                if (!$group) {
                    $res[$idx] = $subthing;
                } else {
                    if (!isset($res[$idx])) $res[$idx] = array();
                    $res[$idx][] = $subthing;
                }
            }
        }

        return $res;
    }