WEBVTT

00:00.680 --> 00:06.440
I will call you back a day two ended up with a lecture in PHP, and in this video lecture we go ahead

00:06.440 --> 00:09.080
and look at associative array.

00:15.830 --> 00:19.580
All right so we've looked at arrays which is the number array.

00:19.580 --> 00:24.290
And we're looking at another array which is called an associative array.

00:24.320 --> 00:29.870
So an associative array means that we're going to deal with keys and values.

00:29.870 --> 00:35.990
So if I go ahead and put in D so can you understand what we're talking about.

00:35.990 --> 00:39.320
So in the previous arrays we discussed about players.

00:39.320 --> 00:42.560
So we're going to still maintain that same players right in here.

00:42.560 --> 00:46.130
So let's go ahead and put an underscore.

00:46.730 --> 00:52.910
Uh so let's go ahead and put in assign which is to create a variable.

00:52.910 --> 00:56.630
And let's scale and give a variable called goals.

00:56.660 --> 01:00.400
Determining how many goals each of these players AWS gave.

01:00.430 --> 01:03.490
Now this is equal to a ray.

01:03.520 --> 01:09.340
And then we go ahead and, uh, move inside a ray.

01:09.340 --> 01:15.880
And the very first elements today is going to be the key way the associative array is going to be the

01:15.880 --> 01:16.420
value.

01:16.420 --> 01:18.490
So let's say tornado.

01:19.150 --> 01:23.440
And uh so we're gonna say it an arrow is equal.

01:23.710 --> 01:27.490
And let me say it gives 35 goals.

01:27.520 --> 01:28.960
Go ahead and put a semicolon.

01:28.960 --> 01:31.690
And and then the next one is Macy.

01:31.930 --> 01:38.560
And uh the associative array is going to be let me say 30 goes.

01:38.560 --> 01:45.850
So and the next one is going to be let me say Sasha.

01:46.030 --> 01:53.260
And uh, let this be equal to 25 goals.

01:53.260 --> 01:57.130
And uh, so you cannot add one more.

01:57.130 --> 02:00.030
So I'll go ahead and track this a little bit Park West.

02:00.030 --> 02:01.320
So we were to add one more.

02:01.320 --> 02:05.550
So the next one we're going to add, we may see this is a seller.

02:05.790 --> 02:12.330
And uh, the next is going to be let's say 20 goes.

02:12.750 --> 02:13.320
All right.

02:13.320 --> 02:18.030
So I'm going to add this to create this array alpha players.

02:18.030 --> 02:23.070
And now the goals which they give is the associative array.

02:23.100 --> 02:26.070
So the very first one here is the key.

02:26.070 --> 02:31.440
So the names the names are the keys white goes which they give is the values.

02:31.440 --> 02:35.010
So ensure that the keys are unique.

02:35.040 --> 02:39.420
The keys must always be unique but the values can be the same.

02:39.420 --> 02:47.490
So maybe each of these players can be 30 goals or true you understand, but they shouldn't be at the

02:47.490 --> 02:51.510
same name in order not to throw an error right in here.

02:51.540 --> 02:56.130
So go ahead and put a semicolon at the end of these so it can be able to check this out.

02:56.160 --> 02:59.090
Then on this card here and uh encode called this out.

02:59.090 --> 03:04.130
So for us to echo this out, Corina say echo, echo.

03:04.160 --> 03:05.270
Dorothy.

03:05.300 --> 03:06.590
Underscore.

03:07.310 --> 03:08.000
Sorry.

03:08.240 --> 03:13.130
Dorothy Rothstein goes because you just want to echo the goes.

03:13.160 --> 03:13.610
All right.

03:13.640 --> 03:22.280
And now we go ahead and impute the keys and not the values, because each of the keys will give us the

03:22.280 --> 03:25.250
corresponding value which is associative array.

03:25.280 --> 03:28.160
Now let's go ahead and say messy.

03:28.250 --> 03:30.800
And we'll go ahead and press semicolon.

03:30.980 --> 03:32.390
And I save this.

03:32.420 --> 03:34.640
Now let's go ahead and refresh this and check it out.

03:34.640 --> 03:36.740
So messy is dirty.

03:37.610 --> 03:38.330
You see that.

03:38.330 --> 03:46.070
And what if we go ahead and change this to Ronaldo and set this.

03:46.070 --> 03:47.480
And let's refresh.

03:47.480 --> 03:50.420
So you can see we have Ronaldo 35.

03:50.420 --> 03:53.000
And that actually works fine.

03:53.030 --> 03:55.760
Now I can also do just like a normal array.

03:55.790 --> 03:58.780
I can also Change their values.

03:58.780 --> 04:00.610
So if all to change the value.

04:00.640 --> 04:04.810
I'll go over here and I'm going to give in the variable name.

04:04.810 --> 04:06.940
And I'm going to say goes.

04:08.470 --> 04:12.010
And then I'm going to add the key.

04:12.070 --> 04:20.740
I'm going to say messy and let mercy be equal to 100 goals.

04:21.820 --> 04:22.540
Semicolon.

04:22.540 --> 04:27.160
And if I should echo this out I'm going to say messy.

04:27.250 --> 04:30.010
And then I'll go ahead and refresh this.

04:30.040 --> 04:35.230
You can see that messy is no longer 30 goals, but 100 goals.

04:35.530 --> 04:42.160
So you can see that you do just normal things you do on the normal arrays right in here.

04:42.160 --> 04:47.260
But what the difference right in here is the keys and the values.

04:47.260 --> 04:49.690
So this has keys and this has values.

04:49.690 --> 04:56.200
So in an array we access our race using the index values.

04:56.200 --> 04:59.560
But One here we assess our race using the keys.

04:59.560 --> 05:03.610
That is the difference between associative arrays and the number arrays.

05:04.210 --> 05:07.990
So each of the keys are mapped to a particular value.

05:07.990 --> 05:10.750
And each of these keys they must be unique.

05:10.780 --> 05:13.510
What the values can actually be the same.

05:14.140 --> 05:15.160
So I hope that is cool.

05:15.160 --> 05:24.040
Now what if you want to check out how many of these goals that is, you can go ahead and let me go ahead

05:24.040 --> 05:26.110
and comment on this.

05:26.110 --> 05:34.270
And then we go ahead and say that this is the equal and then you okay.

05:34.300 --> 05:39.910
So goes right.

05:39.910 --> 05:45.580
So I input global right in here because I want it to autocomplete it.

05:45.580 --> 05:48.910
So equal goes.

05:50.290 --> 05:56.720
And uh we input this into.

05:57.950 --> 06:02.180
Was this because once just want to check how many goes that are here.

06:03.140 --> 06:06.140
Then go ahead and put the counts right in here.

06:06.140 --> 06:09.830
And at the end of this I save this.

06:09.860 --> 06:11.330
Let's check it out for.

06:11.330 --> 06:15.800
So we have four of these keys and values.

06:15.800 --> 06:17.930
So remember that one of these is one.

06:17.930 --> 06:19.160
And this is one.

06:19.190 --> 06:20.480
This is a one.

06:20.480 --> 06:22.400
And this is another one making it four.

06:22.400 --> 06:25.880
So this can actually take a string and not just numbers.

06:25.880 --> 06:38.270
So if I go ahead and say hello and uh if I go ahead and comment on this and let me see, oh, I actually

06:38.270 --> 06:42.350
opened this kind of crisis again with a semicolon.

06:43.460 --> 06:46.820
And, uh, the let me see.

06:46.850 --> 06:48.680
So can you put Ronaldo.

06:51.140 --> 06:53.300
Save this and refresh this.

06:53.330 --> 06:53.750
We have.

06:53.750 --> 06:54.170
Hello.

06:54.170 --> 06:59.360
So it can actually be a string and not just a number only.

06:59.540 --> 06:59.990
All right.

06:59.990 --> 07:01.310
So you can use this as a grade.

07:01.340 --> 07:02.960
Maybe you want to check the grade of students.

07:02.960 --> 07:08.690
You can say Ronaldo is equal to a mrs. B and the Sakai C Salah is D.

07:09.050 --> 07:12.530
So we can use that to actually check the grade of a student.

07:12.560 --> 07:14.720
Let's go ahead and create a simple form.

07:14.750 --> 07:15.380
All right.

07:15.380 --> 07:17.330
So can we use this with our form.

07:17.330 --> 07:23.300
So if I go ahead and create a simple form let's go ahead and say that this is a form so that once we

07:23.300 --> 07:29.900
go into the form and input the number or the name of the player, it shows the goals that is scored.

07:29.930 --> 07:30.530
All right.

07:30.560 --> 07:34.160
So let's go ahead and promise the form right in here.

07:34.970 --> 07:36.410
Now the form is closed.

07:36.410 --> 07:48.470
So we go ahead and given the action and let the action be site dot PHP and let the method be equal to

07:48.500 --> 07:50.570
post method just descending.

07:50.570 --> 07:58.420
And then what we need to do is go ahead and put an input and lead type of the input.

07:59.200 --> 08:05.470
Let it type of the input text, because we're just not to put a name of the player and let the name

08:05.590 --> 08:11.320
again and give the name to be players, because we're dealing with our players right in here.

08:11.350 --> 08:16.150
So now let's go ahead and give this input.

08:17.140 --> 08:19.780
So we're putting that input type right in here.

08:19.780 --> 08:24.250
And the type is going to be a submit.

08:25.360 --> 08:27.070
And God how cool is this.

08:27.310 --> 08:27.940
All right.

08:27.940 --> 08:34.150
So if I should go ahead and go ahead and comment on this I save this.

08:34.150 --> 08:36.190
So I'm able to refresh and check it out.

08:36.430 --> 08:41.350
Now if I go ahead and input Ronaldo it's going to say hello array.

08:41.350 --> 08:42.520
And if you put Messi.

08:42.550 --> 08:45.220
So taxi and the score is five.

08:45.250 --> 08:46.300
Salah is 30.

08:46.330 --> 08:47.830
Sorry is 20.

08:47.860 --> 08:51.670
Now how will you be able to connect this with PHP.

08:51.700 --> 08:53.550
So that is the next thing.

08:53.550 --> 08:56.760
So go ahead and say echo.

08:57.870 --> 09:05.100
And now go ahead and get a variable which is goes.

09:08.700 --> 09:09.630
Goes.

09:09.810 --> 09:12.390
And inside this goes.

09:12.390 --> 09:17.040
You go ahead and pass in the method which is the post method.

09:17.070 --> 09:19.200
All right isn't the square bracket.

09:19.200 --> 09:30.060
So go ahead I say underscore posts and you pass in the name of this input tag which you just created

09:30.060 --> 09:30.780
right in here.

09:30.810 --> 09:33.210
And that is play as.

09:33.210 --> 09:38.130
So always remember to put a semicolon at the end of this and let's save this.

09:38.130 --> 09:47.550
So now if I refresh this and uh so let's go ahead and I'll go ahead and post a comment on this so that

09:47.550 --> 09:50.940
we can be able to deal with only this.

09:50.970 --> 09:57.620
Now let me go ahead and say I put in Macy and let's say this and that is 30.

09:57.980 --> 09:58.790
All right.

09:58.850 --> 10:00.500
So that is 30.

10:01.790 --> 10:04.970
And what if you put Ronaldo.

10:07.250 --> 10:09.500
Gets hit and that is hello.

10:09.710 --> 10:11.000
It can be able to see that.

10:11.000 --> 10:16.970
And what if you put in soccer and hit on submit.

10:16.970 --> 10:18.230
That is 25.

10:18.260 --> 10:19.880
And what of Salah.

10:19.910 --> 10:22.820
And that is 20.

10:22.850 --> 10:24.320
Oh that is Salah.

10:24.470 --> 10:33.770
And that should be a submit okay Salah I use an uppercase S right in here.

10:33.890 --> 10:35.270
And that is 20.

10:35.390 --> 10:35.720
All right.

10:35.720 --> 10:38.660
So you should always be careful because it's case sensitive.

10:38.690 --> 10:39.170
All right.

10:39.170 --> 10:43.940
So let me put this down to lowercase so we don't actually make a mistake.

10:43.970 --> 10:44.570
All right.

10:44.570 --> 10:49.280
So you can see we have been able to use this with every player right in here.

10:49.280 --> 10:52.360
And we are able to get all this and that.

10:52.390 --> 10:53.410
What do you find?

10:53.410 --> 10:55.090
So you put it down on your own.

10:55.090 --> 10:56.260
You play around with it.

10:56.290 --> 10:58.600
You can see how the associative arrays work.

10:58.630 --> 11:05.470
Associative arrays use keys and values, and the keys must always be unique or the values can be the

11:05.470 --> 11:05.890
same.

11:05.890 --> 11:16.090
So if I say I have a sucker to be 80 and ABC is also 80, if I go ahead and put Sakurai's submit, I

11:16.090 --> 11:17.080
still get my 30.

11:17.110 --> 11:21.130
If I go ahead and put messy, I get my dates here.

11:21.130 --> 11:27.730
So the keys has to be different, but the values can be the same or different.

11:27.730 --> 11:30.970
There is no problem and it can actually be a number.

11:31.000 --> 11:33.970
The values can either be numbers or strings.

11:33.970 --> 11:35.110
That is no problem.

11:35.110 --> 11:37.540
That is all about associative arrays.

11:37.540 --> 11:39.910
So go ahead and play around with it and check it out.

11:39.910 --> 11:44.380
And if you have any questions on that this video lecture, please use the question and answer section.

11:44.380 --> 11:46.990
And I'm going to get back to you as soon as possible.

11:47.020 --> 11:47.950
Thank you so much.

11:47.950 --> 11:51.010
And I'm going to see you in the next video lecture.
