在经典的asp中对数组进行分组?

ton*_*yeb 2 vbscript asp-classic

我在ASP中有一个如下所示的数组:

3,5,7,7,3,2,3
Run Code Online (Sandbox Code Playgroud)

我想要做的是将它们与计数分组,这样我就可以:

Number  Count
2       1
3       3
5       1
7       2
Run Code Online (Sandbox Code Playgroud)

这可能吗?如果是这样的话?

Gab*_*oli 7

在asp-classic中没有关联数组..

另一种方法是Scripting.Dictionary

所以

<%
    dim ar
    ar = array(3,5,7,7,3,2,3)

    dim dictArray

    set dictArray = server.CreateObject("Scripting.Dictionary")

    for each i in ar
        if dictArray.exists( i ) then
            dictArray(i) = dictArray(i) + 1
        else
            dictArray(i) = 1
        end if
    next
%>
Run Code Online (Sandbox Code Playgroud)

这创造了你想要的......现在就看到它

<%
    for each i in dictArray
        response.write( i & " : " & dictArray(i) & "<br />")
    next
 %>
Run Code Online (Sandbox Code Playgroud)