Jump to content

Recommended Posts

Posted (edited)

Say I have two arrays:

Local $aArray1[3] = ["one", "two", "three"]

Local $aArray2[3] = [1, 2, 3]

And I want to join them into a simgle 2D Array, resulting in:

$aArray[2][3] = [["one", "two", "three"] , [1, 2, 3] ]

I remember that, with other languages, it's possible to simply do:

$aArray[2][3] = [ $aArray1, $aArray2]

Is there a direct method like this to join arrays, (not by using a loop).

Edited by oasis375
  • Moderators
Posted

Look at _ArrayConcatenate in the help file

#include <Array.au3>

Local $a1[5] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
Local $a2[2] = ["Saturday", "Sunday"]

_ArrayDisplay($a1, "Before")
_ArrayDisplay($a2, "Before")

_ArrayConcatenate($a1, $a2)
_ArrayDisplay($a1, "After")

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Yes, I know how to concatenate two 1D arrays. If you read again my question, you'll notice that I'm talking about a multidim array. I'm trying to join two 1D arrays into a 2D array (with 2 columns).

$aArray[2][3] = [["one", "two", "three"] , [1, 2, 3] ]

Not the same as:

$aArray[6] = ["one", "two", "three", 1, 2, 3]

 

Posted

No, there is no direct method to do what you want to do.
You have to code it yourself. But that's not too hard ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted (edited)

Your arrays are in the wrong orientation. You can use _Predim() to do this - or _ArrayTranspose(). See ArrayWorkshop in my signature.

#include <Array.au3>
#include 'ArrayWorkshop.au3'

Local $aArray1[3] = ["one", "two", "three"]
Local $aArray2[3] = [1, 2, 3]

_Predim($aArray1, 2, True) ; specific to your request
_Predim($aArray2, 2, True)

_ArrayAttach($aArray1, $aArray2)
_ArrayDisplay($aArray1)

Oops, ignore what I just said. Your array declaration syntax is incorrect. 2 columns is easier: simply just attach the arrays in the second dimension.

#include <Array.au3>
#include 'ArrayWorkshop.au3'

Local $aArray1[3] = ["one", "two", "three"]
Local $aArray2[3] = [1, 2, 3]

_ArrayAttach($aArray1, $aArray2, 2)
_ArrayDisplay($aArray1)

 

Edited by czardas

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
  • Recently Browsing   0 members

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