I will call you back a day two ended up with a lecture in PHP, and in this video lecture we go ahead
and look at associative array.
All right so we've looked at arrays which is the number array.
And we're looking at another array which is called an associative array.
So an associative array means that we're going to deal with keys and values.
So if I go ahead and put in D so can you understand what we're talking about.
So in the previous arrays we discussed about players.
So we're going to still maintain that same players right in here.
So let's go ahead and put an underscore.
Uh so let's go ahead and put in assign which is to create a variable.
And let's scale and give a variable called goals.
Determining how many goals each of these players AWS gave.
Now this is equal to a ray.
And then we go ahead and, uh, move inside a ray.
And the very first elements today is going to be the key way the associative array is going to be the
value.
So let's say tornado.
And uh so we're gonna say it an arrow is equal.
And let me say it gives 35 goals.
Go ahead and put a semicolon.
And and then the next one is Macy.
And uh the associative array is going to be let me say 30 goes.
So and the next one is going to be let me say Sasha.
And uh, let this be equal to 25 goals.
And uh, so you cannot add one more.
So I'll go ahead and track this a little bit Park West.
So we were to add one more.
So the next one we're going to add, we may see this is a seller.
And uh, the next is going to be let's say 20 goes.
All right.
So I'm going to add this to create this array alpha players.
And now the goals which they give is the associative array.
So the very first one here is the key.
So the names the names are the keys white goes which they give is the values.
So ensure that the keys are unique.
The keys must always be unique but the values can be the same.
So maybe each of these players can be 30 goals or true you understand, but they shouldn't be at the
same name in order not to throw an error right in here.
So go ahead and put a semicolon at the end of these so it can be able to check this out.
Then on this card here and uh encode called this out.
So for us to echo this out, Corina say echo, echo.
Dorothy.
Underscore.
Sorry.
Dorothy Rothstein goes because you just want to echo the goes.
All right.
And now we go ahead and impute the keys and not the values, because each of the keys will give us the
corresponding value which is associative array.
Now let's go ahead and say messy.
And we'll go ahead and press semicolon.
And I save this.
Now let's go ahead and refresh this and check it out.
So messy is dirty.
You see that.
And what if we go ahead and change this to Ronaldo and set this.
And let's refresh.
So you can see we have Ronaldo 35.
And that actually works fine.
Now I can also do just like a normal array.
I can also Change their values.
So if all to change the value.
I'll go over here and I'm going to give in the variable name.
And I'm going to say goes.
And then I'm going to add the key.
I'm going to say messy and let mercy be equal to 100 goals.
Semicolon.
And if I should echo this out I'm going to say messy.
And then I'll go ahead and refresh this.
You can see that messy is no longer 30 goals, but 100 goals.
So you can see that you do just normal things you do on the normal arrays right in here.
But what the difference right in here is the keys and the values.
So this has keys and this has values.
So in an array we access our race using the index values.
But One here we assess our race using the keys.
That is the difference between associative arrays and the number arrays.
So each of the keys are mapped to a particular value.
And each of these keys they must be unique.
What the values can actually be the same.
So I hope that is cool.
Now what if you want to check out how many of these goals that is, you can go ahead and let me go ahead
and comment on this.
And then we go ahead and say that this is the equal and then you okay.
So goes right.
So I input global right in here because I want it to autocomplete it.
So equal goes.
And uh we input this into.
Was this because once just want to check how many goes that are here.
Then go ahead and put the counts right in here.
And at the end of this I save this.
Let's check it out for.
So we have four of these keys and values.
So remember that one of these is one.
And this is one.
This is a one.
And this is another one making it four.
So this can actually take a string and not just numbers.
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
opened this kind of crisis again with a semicolon.
And, uh, the let me see.
So can you put Ronaldo.
Save this and refresh this.
We have.
Hello.
So it can actually be a string and not just a number only.
All right.
So you can use this as a grade.
Maybe you want to check the grade of students.
You can say Ronaldo is equal to a mrs. B and the Sakai C Salah is D.
So we can use that to actually check the grade of a student.
Let's go ahead and create a simple form.
All right.
So can we use this with our form.
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
go into the form and input the number or the name of the player, it shows the goals that is scored.
All right.
So let's go ahead and promise the form right in here.
Now the form is closed.
So we go ahead and given the action and let the action be site dot PHP and let the method be equal to
post method just descending.
And then what we need to do is go ahead and put an input and lead type of the input.
Let it type of the input text, because we're just not to put a name of the player and let the name
again and give the name to be players, because we're dealing with our players right in here.
So now let's go ahead and give this input.
So we're putting that input type right in here.
And the type is going to be a submit.
And God how cool is this.
All right.
So if I should go ahead and go ahead and comment on this I save this.
So I'm able to refresh and check it out.
Now if I go ahead and input Ronaldo it's going to say hello array.
And if you put Messi.
So taxi and the score is five.
Salah is 30.
Sorry is 20.
Now how will you be able to connect this with PHP.
So that is the next thing.
So go ahead and say echo.
And now go ahead and get a variable which is goes.
Goes.
And inside this goes.
You go ahead and pass in the method which is the post method.
All right isn't the square bracket.
So go ahead I say underscore posts and you pass in the name of this input tag which you just created
right in here.
And that is play as.
So always remember to put a semicolon at the end of this and let's save this.
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
we can be able to deal with only this.
Now let me go ahead and say I put in Macy and let's say this and that is 30.
All right.
So that is 30.
And what if you put Ronaldo.
Gets hit and that is hello.
It can be able to see that.
And what if you put in soccer and hit on submit.
That is 25.
And what of Salah.
And that is 20.
Oh that is Salah.
And that should be a submit okay Salah I use an uppercase S right in here.
And that is 20.
All right.
So you should always be careful because it's case sensitive.
All right.
So let me put this down to lowercase so we don't actually make a mistake.
All right.
So you can see we have been able to use this with every player right in here.
And we are able to get all this and that.
What do you find?
So you put it down on your own.
You play around with it.
You can see how the associative arrays work.
Associative arrays use keys and values, and the keys must always be unique or the values can be the
same.
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
still get my 30.
If I go ahead and put messy, I get my dates here.
So the keys has to be different, but the values can be the same or different.
There is no problem and it can actually be a number.
The values can either be numbers or strings.
That is no problem.
That is all about associative arrays.
So go ahead and play around with it and check it out.
And if you have any questions on that this video lecture, please use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.