public static function setBySelector($array, $selector, $value, $overwrite = false)
    {
        // make sure the array is an array in case we got here through a subsequent call
        // so arraySetElementBySelector(array(), 'item[subitem]', 'value');
        // will call arraySetElementBySelector(null, 'subitem', 'value');
        if (! is_array($array)) {
            $array = array();
        }
        list($container, $subselector) = self::getSelectorParts($selector);
        if (! $subselector) {
            if ($container !== '*') {
                if ($overwrite === true || ! array_key_exists($container, $array)) {
                    $array[$container] = $value;
                }
            }

            return $array;
        }

        // if we have a subselector the $array[$container] must be an array
        if ($container !== '*' && ! array_key_exists($container, $array)) {
            $array[$container] = array();
        }
        // we got here through something like *[subitem]
        if ($container === '*') {
            foreach ($array as $key => $v) {
                $array[$key] = self::setBySelector($array[$key], $subselector, $value, $overwrite);
            }
        } else {
            $array[$container] = self::setBySelector($array[$container], $subselector, $value, $overwrite);
        }

        return $array;
    }