private function explodeTree($array, $delimiter = '_', $baseval = false)
    {
        if (!is_array($array)) {
            return false;
        }
        $splitRE = '/' . preg_quote($delimiter, '/') . '/';
        $returnArr = [];
        foreach ($array as $key => $val) {
            // Get parent parts and the current leaf
            $parts = preg_split($splitRE, $key, -1, PREG_SPLIT_NO_EMPTY);
            $leafPart = array_pop($parts);

            // Build parent structure
            // Might be slow for really deep and large structures
            $parentArr = &$returnArr;
            foreach ($parts as $part) {
                if (isset($parentArr['children'][$part])) {
                    if (!is_array($parentArr['children'][$part])) {
                        if ($baseval) {
                            $parentArr['children'][$part] = ['__base_val' => $parentArr[$part]];
                        } else {
                            $parentArr['children'][$part] = [];
                        }
                    }
                    $parentArr = &$parentArr['children'][$part];
                } else {
                    $parentArr['children'][$part] = [];
                    $parentArr = &$parentArr['children'][$part];
                }
            }

            // Add the final part to the structure
            if (empty($parentArr['children'][$leafPart])) {
                $parentArr['children'][$leafPart] = $val;
            } elseif ($baseval && is_array($parentArr['children'][$leafPart])) {
                $parentArr['children'][$leafPart]['__base_val'] = $val;
            } else {
                $parentArr['children'][$leafPart] = array_merge($val, $parentArr['children'][$leafPart]);
            }
        }

        return $returnArr;
    }