ASP动态多维数组

问题描述 投票:0回答:1

作为 ASP 新手,我尝试从表单创建多维数组。在 php 中就像:

<?php 
    $myArray = array();
    for($i = 0 $i< $myArray.size() $i++){ 
       
    myArray[$i] = array(field1=>"var1",field2=>var2);
    }
?> //syntax not exactly correct but you get the picture

我想用 ASP 写这个,但我无法弄清楚。

我需要从我在这里完成的表单中获取值,然后将这些值放入数组中。

    Function getResults(totalRows)

    dim results() 'my array for results
    for i = 0 to totalRows - 1 

    color = request.form("color"&i)
    width = request.form("width"&i)
    height = request.form("height"&i)


    results(i)("color") = color
    results(i)("height") = height
    results(i)("width") =  width

    response.write("color is " &results(i)("color")
    response.write("color is " &results(i)("height")
    response.write("color is " &results(i)("width")
    NEXT
End Function

我需要返回这个数组才能使用它。 我曾尝试在网上查找,但似乎没有成功。 预先感谢。

multidimensional-array asp-classic
1个回答
5
投票

问题已解决,我使用了不正确的语法,并且必须重新调整数组 - 以防万一这可以帮助其他人

 dim results() 'my array for results
 ReDim Results(totalRows, 3)
 for i = 0 to totalRows - 1 
   results(i,0) = color
   results(i,1) = height
   results(1,2) =  width

   response.write("color is " &results(i,0)
   response.write("color is " &results(i,1)
   response.write("color is " &results(i,2)
NEXT

您可以在另一个循环中替换第二个索引,

© www.soinside.com 2019 - 2024. All rights reserved.