private function arrayParam($value, ArrayType $arrayType, $allowMixedArrayType = false)
    {
        if (!is_array($value) && $value !== null) {
            throw new \InvalidArgumentException('Array value must be an array or null.');
        }

        $inferredTypes = [];
        $res = null;
        if ($value !== null) {
            $res = [];
            foreach ($value as $element) {
                $type = $this->paramType(
                    $element,
                    $arrayType->type() === Database::TYPE_STRUCT ? $arrayType->type() : null,
                    $arrayType->structType()
                );

                $res[] = $type[0];
                if (isset($type[1]['code'])) {
                    $inferredTypes[] = $type[1]['code'];
                }
            }
        }

        if (!$allowMixedArrayType && count(array_unique($inferredTypes)) > 1) {
            throw new \InvalidArgumentException('Array values may not be of mixed type');
        }

        $nested = $arrayType->structType();
        $arrayType = $arrayType->type();

        if (!empty($value) && $arrayType && $arrayType !== $inferredTypes[0]) {
            throw new \InvalidArgumentException('Array data does not match given array parameter type.');
        }

        $typeCode = $arrayType === null && $inferredTypes
            ? $inferredTypes[0]
            : $arrayType;

        if ($nested) {
            $nestedDefType = $this->resolveTypeDefinition($nested);
            $nestedDef = $this->paramType(null, $nestedDefType[0], $nestedDefType[1]);

            $typeObject = $nestedDef[1];
        } else {
            $typeObject = $this->typeObject($typeCode);
        }

        $type = $this->typeObject(
            self::TYPE_ARRAY,
            $typeObject,
            'arrayElementType'
        );

        return [$res, $type];
    }