public static function group(array $array, $key = null, $forceArray = false)
    {
        $results = [];
        $hasArray = [];

        foreach ($array as $index => $value) {
            // List value
            if (is_array($value) || is_object($value)) {
                if (!static::has($value, $key)) {
                    continue;
                }

                $resultKey = static::get($value, $key);
                $resultValue = $array[$index];
            } else {
                // Scalar value.
                $resultKey = $value;
                $resultValue = $index;
            }

            // First set value if not exists.
            if (!isset($results[$resultKey])) {
                // Force first element in array.
                if ($forceArray) {
                    $results[$resultKey] = [$resultValue];
                    $hasArray[$resultKey] = true;
                } else {
                    // Keep first element single.
                    $results[$resultKey] = $resultValue;
                }
            } elseif (!$forceArray && empty($hasArray[$resultKey])) {
                // If first element is sngle, now add second element as an array.
                $results[$resultKey] = [
                    $results[$resultKey],
                    $resultValue,
                ];

                $hasArray[$resultKey] = true;
            } else {
                // Now always push new elements.
                $results[$resultKey][] = $resultValue;
            }
        }

        unset($hasArray);

        return $results;
    }