Jump to content

Declaring multi dimentional arrays


jorgepr13
 Share

Recommended Posts

Is there is a way to do this

$arr[2][2] = [[1, 2], [3, 4]]

but something like this?

$arr[2][2]
$arr[0][2]=[1,2]
$arr[1][2]=[3,4]

because declaring it like this may take a lot of space

$arr[2][2]
$arr[0][0]=1
$arr[0][1]=2
$arr[1][0]=3
$arr[1][1]=4

in the case that you don't want to have all the declarations in the same place that it may look messy and may confuse not knowing in what dimension you are

Edited by jorgepr13
Link to comment
Share on other sites

No, you can't do it the way you described above.

But if you want to fill the array with ascending numbers (1,2,3,4,5...) you can do it in a loop.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You can always do array in arrays, kind of array^2, rather than 2d array

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aHouser[2] = [$aArray1,$aArray2]
For $i = 0 To UBound ( $aHouser ) - 1
   $currentArray = $aHouser[$i]
   _ArrayDisplay ( $currentArray )
Next

This has the advantage of only needing to know the 1 level of dimensions, as well

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Be aware that the Array-in-Array-solution isn't recommended for performance reasons as you can read here at the end of the page.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You can always do array in arrays, kind of array^2, rather than 2d array

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aHouser[2] = [$aArray1,$aArray2]
For $i = 0 To UBound ( $aHouser ) - 1
$currentArray = $aHouser[$i]
_ArrayDisplay ( $currentArray )
Next

This has the advantage of only needing to know the 1 level of dimensions, as well

will it work for differentiated dimensions?

$arr[4][2]
$arr[0][2]=[1,2]
$arr[1][2]=[3,4]
$arr[2][2]=[1,4]
$arr[3][2]=[5,10]
Edited by jorgepr13
Link to comment
Share on other sites

do whatever you want, but syntax must look like:

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aArray3[2] = ["a","b"]
Dim $aArray4[3] = [3,4,5]
Dim $aArray5[2] = [9,10]

Dim $aHouser[5] = [$aArray1,$aArray2,$aArray3,$aArray4,$aArray5]
For $i = 0 To UBound ( $aHouser ) - 1
$currentArray = $aHouser[$i]
_ArrayDisplay ( $currentArray )
Next

edit: for your specific question, i'm thinking no :)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

You can use the line continuation character ("_") to split long lines, example:

#include <Array.au3>

Local $arr[2][2] = [[1, 2], _
                    [3, 4]]

_ArrayDisplay($arr)
Edited by AdmiralAlkex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...