Jump to content

Transpose Array


Recommended Posts

Depends on what you want to do but below is a basic algorithm to do this.

dim $myArray[5][3]=[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]
dim $transposedarray[3][5]

;Transpone the array
for $i=0 to ubound($myArray,1)-1
    for $j=0 to ubound($myArray,2)-1
        $transposedArray[$j][$i]=$myArray[$i][$j]
    Next
Next

;Display the original one
for $i=0 to ubound($myArray,1)-1
    for $j=0 to ubound($myArray,2)-1
        consolewrite($myArray[$i][$j])
    Next
    consolewrite(@crlf)
Next

;Display the newone
for $i=0 to ubound($myArray,2)-1
    for $j=0 to ubound($myArray,1)-1
        consolewrite($transposedArray[$i][$j] & ";")
    Next
    consolewrite(@crlf)
Next
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...