oasis375

Array joining. Language limitation?

5 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  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

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