AutoIt 从数组中获取子数组
一段简单的代码,我们想要将数组的元素(又是另一个数组)存储在另一个变量中:
Global $arr[1][2] = [ [1, 2] ]
Global $sub = $arr[0]
如果我们
Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Global $sub = $arr[0]
Global $sub = ^ ERROR
写
Global $arr[1][2] = [ [1, 2] ]
Global $sub[2] = $arr[0]
我们得到
Missing subscript dimensions in "Dim" statement.:
Global $sub[2] = $arr[0]
Global $sub[2] = ^ ERROR
如此简单的任务,但我没有找到方法做吧。不知道。请帮忙。
Simple piece of code, in which we want to store the element of array (which in turn is another array) in another variable:
Global $arr[1][2] = [ [1, 2] ]
Global $sub = $arr[0]
And we get
Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Global $sub = $arr[0]
Global $sub = ^ ERROR
If we write
Global $arr[1][2] = [ [1, 2] ]
Global $sub[2] = $arr[0]
We get
Missing subscript dimensions in "Dim" statement.:
Global $sub[2] = $arr[0]
Global $sub[2] = ^ ERROR
So simple task, but I didn't find the way how I can do it. Have no idea. Please, help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在创建一个二维多维数组,而不是数组内的数组。两者的区别如下:
多维数组:
数组内的数组:
在 AutoIt 中的大多数情况下,您会更喜欢多维数组。另一个数组中的数组会创建原始数组的副本,因此您会损失一些性能,并且对副本的修改不会影响原始数组。
最后,更喜欢使用 Local 关键字来定义变量,而不是 Global 关键字。如果使用 Local 关键字声明变量,则可以避免污染全局名称空间。
You are creating a multi-dimensional array with 2 dimensions, not an array inside of an array. The difference between the two is as follows:
Multi-dimensional array:
Array inside array:
In most cases in AutoIt you will prefer a multi-dimensional array. An array inside another array creates a copy of the original array, so you lose some performance and modifications to the copy don't affect the original.
Finally, prefer to use the Local keyword to define variables instead of the Global keyword. If you declare variables with the Local keyword you avoid polluting the global namespace.