‫Welcome back.
‫Now that you're a pro in a race, let's go ahead and create a 2D array or in general, multi-dimensional
‫arrays, because arrays cannot just be one line of entries.
‫They can be two dimensional, three dimensional or even multi dimensional further on.
‫So let's create a very simple 2D array and I'm going to create a string to the array.
‫And what I need to do here is instead of leaving the square brackets empty, I enter a comma in there
‫or I put a comma in there, and afterwards I give it a name.
‫So this would be an example for a matrix.
‫So we have a 2D array which is of type string and it's called matrix.
‫So that's how I can declare a 2D array, declare to the array.
‫So now if I want to declare a 3D array, it's pretty simple as well.
‫Three D array.
‫Now I do it with integers just so you see that it works otherwise as well.
‫And I'm going to call that down three D.
‫So that's how you can create a3d array.
‫And as you can see, it's based on the commas.
‫So one comma, two D, two commas, three D, four commas, five D and so forth.
‫I did skip the three commas, which would be 40, but that's how you can simply create multi dimensional
‫arrays.
‫Well, that's how we can declare them.
‫Now let's have a look at how to initialize them.
‫So I'm going to create a new two dimensional array, two dimensional array, and I'm going to call that
‫one int array, two DX.
‫I'm going to keep it simple.
‫And in order to create it, I need to use a new then the data type again.
‫And here I need to declare how many dimensions we have.
‫So in this case one dimension more than to general one.
‫So it's two dimensions in total, and then I need two curly brackets.
‫And what I need to do here now is to go ahead and enter the different rows.
‫So I'm going to create a row of one, two and three separate by comma, four, five and six, separate
‫by comma and seven, eight and nine.
‫So that would be an example of a two DX array, which is a matrix.
‫So pretty much the same thing that we had here.
‫And I start off with one even though the array itself starts with zero.
‫So in order to access this one, I would need to do the following.
‫I can simply write it on the console.
‫So see w double tap.
‫And actually what I want to access is the five.
‫It's much more interesting, I'd say.
‫So I'm going to say central value is and then it's going to be array two DX and then in the square brackets
‫I enter which positions I want to access.
‫So in my case I want to access the position one and one.
‫Why is it one and one?
‫Well, that's row number zero.
‫That's row number one.
‫So this is the row one that I want to access.
‫So this one here and that one is index one within that row.
‫So this four is index zero, five is index one and six is index two.
‫So you could say row zero here, row one and here, row two.
‫All right.
‫So that's pretty much what we do here.
‫And then zero, one, two and so forth.
‫So based on how many entries you have here, this is how you can simply access it.
‫So now let's check it out.
‫Let's read a key so that it doesn't disappear and we are central value is five.
‫All right.
‫So this is how you can access the five now for you as a little challenge.
‫Try to access the seven.
‫All right.
‫I hope you tried it.
‫So in order to access seven, I need to use row two.
‫And then which index is it at zero.
‫So to zero is going to be our seven.
‫So let's run it again.
‫Central value is seven.
‫All righty.
‫So there we are.
‫This is how you can use it to DX array if you want to run a3d array, that's a bit more complex in terms
‫well, it adds a whole dimension, but the concept is the same.
‫So then you would have well, I'm just going to create a very simple three d array, just so you see.
‫All right.
‫So I went ahead and I created this three D array.
‫So you have the curly brackets, which is the first dimension, then curly brackets again second dimension,
‫and then the curly brackets again, which is the third dimension.
‫So you have your depth, your height and your length pretty much if you see it as a3d object, for example.
‫Right?
‫So if I would like to access those, I use string in this case because it's easier to demonstrate it.
‫So if I would like to access this first number, I would have to use 000 in order to get that.
‫So let me show you that this is in fact true.
‫So I'm just going to copy those two lines.
‫Actually, I'm going to cut them out.
‫And I want to get not the central value, but the value is and I'm just going to use here the three
‫D array every three D and I want to access position one, one and zero just as an example.
‫Let's run this.
‫And as you can see, the value is 110.
‫So that might be rather well, weird or simple because you'd say, okay, this is what you entered here.
‫110.
‫Yeah, that's because I named the entries the exact same way that I need in order to access them.
‫So let's say I add another row here and I'm going to use zero.
‫I'm just going to call that one.
‫Hi there.
‫And what's up?
‫So this is pretty simple.
‫Nothing has changed.
‫Except for this one here.
‫As you can see, this array here is not happy anymore or this piece of the three D arrays are not happy
‫anymore because here we had three rows and here we only have two rows.
‫So I need to add another one and here another one and last entry.
‫So just call them that way.
‫So if I now let's say I want to access this high there actually try to do that yourself.
‫Try to enter the correct value in order to access.
‫Hi there.
‫I mean in here, access it.
‫All right.
‫So we said that this is zero.
‫At the first point.
‫This is zero one, actually zero zero here.
‫This row this row is zero one, and this row should be zero two then.
‫So 020 will be high there.
‫So let's access that 020 and let's run it.
‫And as you can see here, it says the value is high there.
‫If I want to access last entry, same approach.
‫This row is one zero.
‫This row here is one one.
‫So this row here will be one two.
‫So we access one, two and one in order to get last entry.
‫So let's run it and we see the values last entry.
‫Okeydokey.
‫So I could go deeper into that.
‫But I think the principle is clear and this is simply how you can create a3d array.
‫And by the way, there are different ways to create multiple dimension arrays.
‫For example, I could also specify the dimensions earlier on, right?
‫So I could say for example and array I'm going to call that one actually string array to D string is
‫a new string.
‫And here I need to specify, for example that I want to have three rows and two entries per row and
‫that one will be, for example, one, then we have two, then we have three, four and so forth, which
‫means and here we have five and six.
‫So that's another way to do it, right?
‫So I can specify it at that point here so that I need three rows, which is going to be that row, that
‫row here and that row.
‫And actually like this.
‫So that's how I can specify how many entries I want to have.
‫Right.
‫Now for you as a little challenge try to change the for to chicken.
‫Just change it to chicken, even if you're a vegan.
‫All right.
‫I hope you tried it.
‫So let's try that.
‫It's going to be array, string or array to the string at the position.
‫And let's check.
‫This is row zero.
‫This is row one and four.
‫Should be one and one then.
‫And I'm going to change that to chicken.
‫And now let's see the value.
‫So I say array two d string at the position of one and one.
‫And now let's see if we get our chicken.
‫The value is chicken.
‫Great.
‫So now you can see how you can change the value of an entry within a two array.
‫So let's say you have an array or you have a name of an array and you don't know how many dimensions
‫it has.
‫So in order to find out the dimensions, let's go ahead and do that.
‫Actually, I'm going to create a new variable.
‫I'm going to call it in dimensions.
‫And it's going to be array to d string that rank.
‫And what rank does is get the rank, the number of dimensions of the array.
‫So if one dimensional array returns one that a two dimensional array should return to.
‫So dimensions now should be two in this case because the 2D string has two dimensions.
‫So I'm just going to print the dimensions out now and let's run that.
‫And it says the value is two.
‫So in case you want to figure out which amount of dimensions a variable has that you get, for example,
‫in this case it's simple, but in more complex cases, you could get that as an argument.
‫And you well, maybe your program runs with different dimensions.
‫It accepts multiple different dimensions, not just the two dimensional array, maybe also a three dimensional
‫array and so forth.
‫And you would like to know how many dimensions the array has before you work with it.
‫So that's how you could figure it out.
‫By the way, you can also create an array without specifying the rank.
‫So in our cases we have always specified the rank.
‫And here we said, okay, we have two dimensions.
‫We have three dimensions and so forth.
‫But what we did that here as well, we need to do that still on that side, but we don't need to do
‫it on the right hand side of our equal sign.
‫So I'm going to show you a little example inch and it's going to be an array two DX and I'm going to
‫call it too.
‫So it's just going to be a different array.
‫And in here I can simply use the square or the curly brackets here to create the array.
‫So as you can see, I have a two dx array now it doesn't complain and I didn't need to use this new
‫string or new end kind of thing where a specified the rank.
‫So it automatically knows.
‫Okay.
‫It's a tree rank by this declaration here.
‫However, if you have already declared an array.
‫So let's say we have our matrix, we have declared it here.
‫I cannot go ahead and let me actually do it here.
‫I cannot just go ahead and say metrics is going to be it's a one to.
‫And it's around curly brackets here as well.
‫So this is something that you should not do.
‫Now, this is going to return an error.
‫It doesn't accept that approach.
‫All right.
‫So don't do that, just so you know.
‫But when you create it, you can initialize it that way straight away.
‫All right.
‫So that was it on multi dimensional arrays in the next video, that will be a little challenge where
‫you actually will need to use two dimensional arrays.
‫We're going to create a little tic tac toe clone, and you should try to build that yourself in the
‫next video.
‫So be prepared and make sure that you understand two dimensional arrays, how to use them, how to access
‫elements and so forth.
‫All right.
‫So see you in the next video.