WEBVTT

00:00.380 --> 00:03.530
I will call you back again to another video lecture in PHP.

00:03.530 --> 00:08.960
And in this video lecture we go ahead and look at arrays in PHP.

00:16.280 --> 00:25.820
Oh, I saw arrays are very important in PHP development because it plays a vital role in collecting

00:25.850 --> 00:28.130
large number of information.

00:28.430 --> 00:37.310
Now we have on the screen you can see I have a different variables and I have first one player, one

00:37.310 --> 00:39.680
player, two, three, four and five.

00:39.710 --> 00:45.110
And now it is easy for me to go ahead and see equal.

00:45.140 --> 00:48.800
Let me say player one.

00:48.950 --> 00:55.670
And if I go ahead I'm going to get okay.

00:55.670 --> 00:58.880
So I have an error right in here.

00:58.910 --> 01:05.580
And that is says unexpected end of pi and In line nine.

01:05.610 --> 01:05.970
All right.

01:05.970 --> 01:08.040
So here I didn't close this.

01:08.040 --> 01:10.920
So this place is not closed.

01:10.950 --> 01:13.200
Now go ahead and check it out again.

01:13.200 --> 01:15.330
So I have a Ronaldo right in there.

01:15.720 --> 01:23.520
So what happens here is that if I want to create a variable and I'm creating different variables of

01:23.520 --> 01:26.310
a different players.

01:26.310 --> 01:28.530
And this is a collection of players.

01:28.530 --> 01:37.230
So it is easier for me to use an array and put everything in just one variable because array is descending

01:37.230 --> 01:38.370
as variables.

01:38.370 --> 01:45.750
But the difference between arrays and a specific individual variables is that each of this variable

01:45.780 --> 01:52.860
just collects one piece of information, it stores just one piece of information, which is just player

01:52.860 --> 01:53.760
one stars.

01:53.790 --> 01:54.420
Ronaldo.

01:54.450 --> 01:58.860
What if we should change this players to an array?

01:58.890 --> 02:03.270
We can be able to collect everything and we can actually access this.

02:03.270 --> 02:08.010
So if I want to access player three, I'll go ahead and echo.

02:08.460 --> 02:09.640
Uh, this is uh.

02:13.210 --> 02:14.860
Player four right?

02:14.890 --> 02:17.080
Player four and I forgot how to run this.

02:17.110 --> 02:19.660
We can see it now.

02:19.690 --> 02:25.300
I will go ahead and, uh, then go ahead and comment on this.

02:25.570 --> 02:25.990
All right.

02:26.020 --> 02:33.850
So I'll go ahead and comment on this, and, uh, I'll go ahead and remove this.

02:33.880 --> 02:36.010
Now, the echo has not run in there.

02:36.040 --> 02:37.720
What to create an array.

02:37.750 --> 02:43.000
Because an array helps us to collect multiple information.

02:43.000 --> 02:48.670
So it is a container that helps us to collect multiple information of the same elements.

02:48.670 --> 02:54.370
So the elements is going to be just the same let's say for players instead of creating different different

02:54.370 --> 03:01.180
players we go ahead and create just an array of players and everything is added.

03:01.180 --> 03:04.390
An array is going to be an element.

03:04.390 --> 03:10.960
So let's go ahead and create a variable called uh player.

03:10.960 --> 03:16.380
And uh let's this player go ahead and have an upgrade.

03:16.620 --> 03:17.070
All right.

03:17.100 --> 03:18.210
So I click on that.

03:18.210 --> 03:21.480
And now I shouldn't just go ahead and do that.

03:21.510 --> 03:23.400
Let me go ahead and say an array.

03:24.810 --> 03:25.410
All right.

03:25.410 --> 03:30.000
Now it's good to have an open and close parentheses and semicolon at the end.

03:30.030 --> 03:31.740
Now I'll go right in here.

03:31.770 --> 03:33.150
I'll take a Ronaldo.

03:33.330 --> 03:37.230
And that is the first element you're going to put in there.

03:37.260 --> 03:41.310
Now we'll go ahead and collect a messi.

03:41.310 --> 03:44.550
That is the second element right in there.

03:44.880 --> 03:52.590
Now we go over here I collect Mbappé and we go right in here and publicity.

03:52.620 --> 04:00.870
So the next one is a Ousmane and then we go ahead and put in there.

04:00.990 --> 04:03.510
Now the last one is Jorge.

04:03.540 --> 04:05.250
You know I'm also a player.

04:05.250 --> 04:08.940
So let's go ahead and put in there.

04:08.970 --> 04:11.340
Now we have collected all these.

04:11.340 --> 04:16.590
You will not ask me how can we be able to display this information?

04:16.590 --> 04:18.340
Permission is that ever possible?

04:18.340 --> 04:23.920
So using an array we are going to use what is called index.

04:24.160 --> 04:28.120
So now over here let's go ahead and say something.

04:28.150 --> 04:32.140
The very first one here Ronaldo is is index zero.

04:32.170 --> 04:36.010
The next one here is our Messi is index one.

04:36.010 --> 04:39.220
Then the next one here is going to be index two.

04:39.250 --> 04:42.700
Then the next one here is index three.

04:42.700 --> 04:45.400
And the last one here is index four.

04:45.430 --> 04:52.810
So whenever you are using an array whatever you have is an index inside of that array.

04:52.840 --> 04:56.470
So it starts from index zero and not one.

04:56.500 --> 05:00.460
So if I should call Ronaldo I should be calling index zero.

05:00.460 --> 05:03.220
And whatever that is there we print it out.

05:03.760 --> 05:11.230
Now let's go ahead and comment on this so that we don't run into an error when we run this code.

05:11.260 --> 05:15.640
Now let's go ahead and equal out player.

05:15.640 --> 05:18.370
And then we're going to use a bracket.

05:18.370 --> 05:21.410
And there if I want to assess, Missy.

05:21.440 --> 05:26.300
I'll go ahead and put a layer one that is index one.

05:26.330 --> 05:30.200
Now I'll go ahead and save this and let's check it out.

05:30.230 --> 05:32.870
So we have a fatal error.

05:32.870 --> 05:38.180
And that says of course undefined player.

05:38.180 --> 05:38.930
And.

05:41.480 --> 05:43.730
In line 17.

05:43.760 --> 05:48.890
And let's go over here and check out what is the problem.

05:48.890 --> 05:53.330
So this is player and this is player.

05:53.360 --> 05:58.040
So what happens is that we missed the dollar sign.

05:58.040 --> 06:00.680
So we missed the dollar sign in line 17.

06:00.680 --> 06:03.590
And let's go over here and refresh this again.

06:03.590 --> 06:06.140
So we have Missy right in here.

06:06.380 --> 06:13.880
So now always remember to put the dollar sign I sorry for missing out the dollar sign on this.

06:13.910 --> 06:17.270
Now let's go ahead and check out index zero.

06:17.270 --> 06:21.050
And then let's go ahead and check it out Coronado.

06:21.080 --> 06:23.600
And let's check out index four.

06:23.600 --> 06:26.280
And uh, let's go ahead and check it out.

06:26.280 --> 06:27.720
And that is George.

06:27.720 --> 06:34.680
So using the iris you can be able to collect so many elements.

06:34.680 --> 06:38.280
So whatever it is inside the array is an element.

06:38.880 --> 06:45.180
And you can access these elements using the index numbers starting from index zero.

06:45.210 --> 06:49.470
The very first element in an array is index zero.

06:50.370 --> 06:53.010
Now I cannot change this as well.

06:53.040 --> 06:54.180
Let me go ahead and see.

06:54.180 --> 06:56.640
I want to change index two.

06:56.670 --> 07:01.950
If I want to change index two, go ahead and remember to put the dollar sign when we say player.

07:01.950 --> 07:05.820
And uh let's go ahead and say index two.

07:05.850 --> 07:09.870
Now changes to any name.

07:09.870 --> 07:14.010
So which name are we going to put them in and say this is a seller.

07:14.100 --> 07:16.770
Now go ahead and press semicolon.

07:16.770 --> 07:22.530
And I've also printed out the index to go ahead and pass index two at the echo of the players and the

07:23.100 --> 07:23.640
refresh rate.

07:23.640 --> 07:24.270
Let's check it out.

07:24.270 --> 07:25.680
So that is seller.

07:26.160 --> 07:29.240
So you can be able to see you can change any name.

07:29.240 --> 07:33.770
You can be able to change any index in that way.

07:33.830 --> 07:36.410
So there are many things to do using an array.

07:36.410 --> 07:39.500
So as time goes on we go ahead and check out more on that.

07:39.500 --> 07:42.470
And we play around arrays.

07:42.590 --> 07:49.850
That is very interesting learning about array because without an array, if you want to collect a large

07:49.850 --> 07:56.060
elements of the same category, you will be creating different variables.

07:56.060 --> 07:59.360
And that that will make your code not to look very clean.

07:59.390 --> 07:59.990
All right.

07:59.990 --> 08:05.690
So with this which we just did right in here, you can be able to see that we created something so good.

08:05.690 --> 08:10.100
And it looks very nice and a very clean.

08:10.100 --> 08:13.430
So thanks to array for making it very simple for us.

08:13.430 --> 08:16.550
And I believe that you too.

08:16.580 --> 08:17.630
You love what you are seeing.

08:17.630 --> 08:19.700
So pull it down, play around with it.

08:19.700 --> 08:24.950
And if you have any question under this video lecture, please use the question and answer section and

08:24.950 --> 08:27.440
I'm going to get back to you as soon as possible.

08:27.470 --> 08:28.430
Thank you so much.

08:28.430 --> 08:32.120
And I'm going to see you in the next video lecture.
