PHP-and-MySQL/C2/Multi-Dimensional-Arrays/English
From Script | Spoken-Tutorial
Time | Narration |
---|---|
0:00 | A multdimensional array is an array inside which you can store other arrays. |
0:06- 0:08 | It is very similar to the associative array. |
0:09- 0:14 | However, the associates for this array are arrays themselves. |
0:15- 0:18 | For a better understanding, let us start the program. |
0:19- 0:24 | I will create a program that lets you see the position of a letter in the English
alphabet. |
0:26- 0:32 | For example, if I give the value 1, it should echo out "A" in position 1. |
0:33- 0:37 | If I give the value two it would say "B" in position 2. |
0:38- 0:42 | And for three, it will say "C" is in position 3, and so on. |
0:43- 1:45 | First I will create my own array. |
0:53- 0:57 | And just for easy viewing, I will bring this down. |
0:58- 1:00 | You are welcome going to do so yourself. |
1:01- 1:06 | And inside. I will create my own array, which I will call ‘ABC’. |
1:10- 1:11 | That will be the array. |
1:15- 1:20 | Instead of putting a value here, as we did before, we have an array inside. |
1:24- 1:31 | And inside these, will be the values, for example, Capital A, B, C and D. |
1:32- 1:35 | These values are separated by commas. |
1:51- 1:56 | And then we type “123” and that is equal to an array. |
1:45- 1:50 | Now we’re just going to have ‘1,2,3,4, and that’s it. |
1:53- 1:58 | Down here, I’ll show you how to echo out specific data inside the array. |
1:59-2:01 | We’ll call our main array. |
2:03- 2:04 | And we’ll call this array as well. |
2:05- 2:12 | And then the position of what you want inside the array. So it’s an array inside an array. |
2:13-2:18 | So I will type ‘echo’ and then ‘alpha’ which is our main array. |
2:19- 2:22 | And then inside square brackets, ‘ABC’. |
2:23- 2:29 | And next, inside square brackets, the position of the element you want to retrieve. |
2:28- 2:34 | Now, for example, is going to echo "A". |
2:35- 2:44 | Let us give that a run - and we got "A". |
2:47- 2:51 | Changing this to ‘123’, will hopefully give us "1". |
2:54- 2:56 | As you can see here. |
2:57-3:04 | So we've made our two basic arrays inside our main arrays, and we’ve learnt to call it. |
3:05- 3:11 | Now I’m going to create a new program to find out the position of a letter in relation to its number. |
3:13- - 3:26 | I’m going to type up here ‘ postion = 0’, since 0 is the beginning. |
3:30- 3:35 | Now I will echo out ‘Letter something is in position something’. |
3:39- 3:40 | This is quite simple. |
3:42- 3:51 | We enter a position here, say 3. Since C is in position 3 in the alphabet, we get C. |
3:53- 3:59 | So , to echo out our letter, if I am going to replace the first blank with ‘alpha’. |
4:02- 4:03 | ABC |
4:05- 4:06 | 'pos' |
4:07- 4:09 | as 'pos' represents our position. |
4:11- 4:17 | So then, the position will be - Alpha... 123 |
4:19- 4:22 | And then the position, ‘pos’. |
4:23- 4:26 | At the moment, position is equal to 0. |
4:29- 4:35 | We type ’echo something’. So this is position zero. |
4:36- 4:46--?? | Position zero inside the internal array “ABC”. So in actual fact, we are saying that A is in position 0, |
4:47- 4:55 | which is this array, 123 and that is position zero. So actually we are saying that letter A is in position one. |
4:55- 5:04 | Lets run this. Okay. A is in position 1. Let’s change this to 1. |
5:05- 5:17 | Refresh. Letter B is in position 2. Now what I will do to make this application fully functional and easy to navigate, is eliminate the necessity to write zero for 1. |
5:21- 5:29 | So I will put ‘-1’ at the end and put 1 in brackets for better legibility. |
5:30- 5:44 | So, position one minus one is infact zero. So, writing 1 will give the same result as 0. Writing 2 will give us the same result as writing 1... So letter B is in position 2. |
5:44- 6:01 | So if I put 1 we get A is in position 1. If I put zero here; there is no position -1; so we get “letter in position”. So we don’t have the letter or the position. |
6:02 onwards | So, I’ve made that a bit more user-friendly. Thanks for watching! |