Jump to content

Copying A Multi Dimensional Array


cothedo
 Share

Recommended Posts

I have a multi-dimensional array variable that I need to copymyArray1[x][y] and myArray2[x][y]Now, I can't just do this: myArray1 = myArray2The new array will only create a reference to the original array (In other words, when I change a value in the new array, the original will also be changed). For a single dimensional array, you can use the "slice" method to copy an array, without it becoming a reference to the original. But how can you use "slice" for multi-dimensional arrays? I tried to google it, but couldn't find anything.

Link to comment
Share on other sites

Interestingly, Jesh's method seems to work no matter what gets stored in the array variables. I tried this where one of the second-order array variables held a two-dimensional object, and everything copied just fine. I had imagined some hideously recursive method, but it looks like you only have to go one level deep in order to grab everything.

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

×
×
  • Create New...