Hello, in this video I am going to cover associative arrays. So if you haven't already watched the array video, highly recommend that. And once you've washed up, feel free to come. Okay, so this is an array, I actually get rid of this because this is demonstrating why you might want to use an array. I'll get rid of this. And, you know, that's an array and that's how we would basically use it.
So the way we actually access an item is by specifying the index and the index starts at zero. So 012 and three, and associate two associative array, it basically associate a name they use specify a, you know, a unique key to the particular value. So if you don't want to do 0123, for example, then you don't have to, I'm gonna use a different example just to you know, demonstrate this or you know, just to illustrate it a bit better. $30 call equals array. Let's say the call has a few different properties it has to make for let's say BMW say that the model one of my favorite BMW is at a 50 fee. On the year I think I know it's in 19 so the BMW 850 CSI Yeah, let's choose 1991 That was my birth year 1990 won.
That's top speed as well. So top speed. Do they have this information here? They do not. So instead of top speed, I am just going to put Now prefer the free one over, you know these ones and two three I pro so instead of that also, you know the engine type. So Angie in the 12 for example, if I want to access the properties and if I want to print it out, so I want to print out the year for example, I would do dollar car and two because it's the first element so 012 save that.
Reload, we get 99 Yeah, that works fine. Fantastic. What happens if I was to add you know, know a piece of information here. Let's say if I didn't know the color, black to do like the red one as well read. This no longer refers to the year anymore and even If we kept the order the same as we add more and more information to this array, it's just going to be hard to manage, you know, saying that zero is the main one is, you know, the model two is the color three, the year four is the engine size, etc, we have an associative array, we can assign a unique key, which can be descriptive of what the information is. And remember, this doesn't have to be you know, a string so we could have this one other numbers on that, that one of the number and print that as you can see, we get that, but the actual key will have to be a string.
So let me show you how to do that. All you do is press bring sound. So make, then you put equals greater and this basically says associate this value with this name, will do the same for the next one. So this is The model to model this ASD and yes, I'm spelling it the British way as well for the year. And finally, this will be the engine. Now instead of, you know, if we reload that, we get an error because it's no longer defined by your position numbers is defined by keys.
So if I want to die originally referred to the color, or you know the engine for you know, the year for example, you just put Yeah, and there we go. If I want the engine, I don't really need to look where it is engine to get the engine size. So that is what an associative array is. And that is how you utilize an associative array in a later video when I get on To control structures such as loops, I am going to cover how to loop over an entire array to them are what an array is, without having to manually specify the, you know, the, the method for indexing it wherever it's the number method, the associative method, but that's in a later video when we get on to loops. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.