·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP网站建设 >> ASP将两个数组合并为一个数组函数 array_merge()

ASP将两个数组合并为一个数组函数 array_merge()

作者:佚名      ASP网站建设编辑:admin      更新时间:2022-07-23

<%
    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.

    ' Merge two arrays into one.
    function array_merge(byVal firstArray, byVal secondArray)
        dim totalSize
        dim i
        dim combinedArray
       
        ' Ensure that we're dealing with arrays.
        if not isArray(firstArray) then
            firstArray = Array(firstArray)
        end if
       
        if not isArray(secondArray) then
            secondArray = Array(secondArray)
        end if
       
        ' Set up the new array.
        totalSize = uBound(firstArray) + uBound(secondArray) + 1
        combinedArray = firstArray
        redim PReserve combinedArray(totalSize)
       
        for i = 0 to uBound(secondArray)
            combinedArray(uBound(firstArray) + 1 + i) = secondArray(i)
        next
       
        array_merge = combinedArray
    end function
%>