我需要在VBScript中迭代数组中的所有元素,但它的维度是未知的。我怎么能这样做?
在Java中,例如,多维数组是数组数组,您可以使用子数组。我不知道如何在VBscript中做到这一点。
感谢任何帮助。
更新:可以通过对阵列使用For Each循环来解决此任务。那么,什么超越For Each循环?它是如何实现的?
答案 0 :(得分:2)
您可以创建Function
或Sub
来递归检查数组中的键是否也是数组。以下是一些示例代码:
<%
' Simple sub to just loop through the array and echo its values
Sub array_values(array_value)
Dim i
If IsArray(array_value) Then
For i = LBound(array_value) To UBound(array_value)
If IsArray(array_value(i)) Then
array_values array_value(i)
Else
Response.Write array_value(i) & "<br>"
End If
Next
End If
End Sub
' Sample array
Dim a
a = array( _
array("1", "2", "3"), _
array("a", "b", "c", _
array("e", "f", "g", _
array("h", "i", "j", _
array("k", "l", "m", _
array("n", "o", "p", _
array("q", "r", "s", _
array("t", "u", "v", _
array("w", "x", "y") _
) _
) _
) _
) _
) _
) _
) _
)
array_values a
%>