Jump to content
oasis375

Array joining. Language limitation?

Recommended Posts

oasis375

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

Share this post


Link to post
Share on other sites
oasis375

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]

 

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
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

×