public function mergeSharedConfiguredRulesWithCreateOrUpdate($shared, $specific, $replace = false)
    {
        // If specific is flagged false, then base rules should be ignored.
        if ($specific === false) {
            return [];
        }

        // Otherwise, make sure the rules are merged as arrays
        if ($specific === null || $specific === true) {
            $specific = [];
        }

        // In replace mode, rules should be merged in from shared only per key, if present as value.
        // When shared rules are merged in specifically like this, their 'value-only' key marker is
        // replaced by the actual key-value pair from the shared rules.
        if ($replace) {

            $sharedKeys = array_filter(
                $specific,
                function ($value, $key) {
                    return is_string($value) && is_numeric($key);
                },
                ARRAY_FILTER_USE_BOTH
            );

            // After this, there may still be string values in the array that do not have (non-numeric)
            // keys. These are explicit inclusions of form-field rules.
            $specific = array_filter(
                $specific,
                function ($value, $key) use ($shared) {
                    return ! is_string($value) || ! is_numeric($key) || ! array_key_exists($value, $shared);
                },
                ARRAY_FILTER_USE_BOTH
            );

            return array_merge(
                array_only($shared, $sharedKeys),
                $specific
            );
        }

        return array_merge(
            $shared ?: [],
            $specific
        );
    }