What are Associative Arrays in PHP

today we're going to talk about something called associative arrays inside PHP and associative arrays is slightly different from what we've done in the past where as an example like they want to have here is what we call an index array now indexed array is simply we have a variable is equal to an array that has some kind of data inside of it so right now have Daniel Nelson and my age so we had three pieces of data inside this array now we want to echo this out inside the browser i can do an echo but we say they have variable data brackets then we can write some kind of number inside the brackets for example of one Daniel inside the browser and write 0 because my data is numbered like 012 so we always start at zero so this is what we've done in the past now what if i want to do something that makes a bit more sense when we actually named these data inside the race then we can do something called an associative array now the main difference here is that instead of writing numbers inside my echo when I want to exit out is they can actually write some kind of name to be named these different data so let's say I want to echo out Daniel just going to refresh the browser you guys can see I do actually Daniel I can go back into my code and I can create a key for each of these data we have inside the array now a key is basically the name to put inside the data brackets down here in order to get out the specific data want to get out now in order to create a key we can go back into the array we can say we have a string that is called maybe first as a first name then i'm going to give this key value by writing equal to greater than which points to a value which is Daniel so now basically just named this data first now we can go and do this to the second data as well by going into it and riding double quotes because you create a string call this one last and then again we point to a value which in this case is Nelson now just to make this a little bit easier to look at I'm just going to go and move to stand to next line so after each come out to get this in separate lines like so so now we only have one piece of data left which is my age I'm just going to give this one string as well i'm going to say h and then again i'm going to give it a value as 25 so right now we named these different data and I can actually go into my code down here we have echo data and teens the value not just to show you guys if we're going to refresh you guys can see you get undefined offset 0 because it doesn't understand what's your means inside my echo now if I go in and say that we have a string called first and save it you guys consider get Daniel because now we changed the name from an indexed array which is numbers into whatever we want to call this data inside the array now this is very useful to naming things because right now if I were to get out the first name of this array I wouldn't understand we're in the sequence it is if I created this array long time ago and I don't remember that you know the order of the data now another one can create an associative array is if i go ahead and delete this data at least delete the first part of it or the last part of it we have variable data i can say brackets create a string so i can say this one is called first then I can set it equal to a string called Daniel second spell it correctly there we go so now we have the first data inside our data very our data array which is equal to Daniel and we already named it first of course and go ahead and carpet is down two more times just teens the data we have in here are the names to last and 2h then again change the values for Nelson and 25 if i were to echoes again you guys can see we still get Daniel if you were to print our this just as he looks like like so and put the variable data inside the printer function you can actually see the full array inside the browser as you guys can see we have the array then we have the first data which in this case is not zero animals first which points to a value as Daniel then we have last which points to a value as Nelson and they have aged two parts to 25 so this is how we can create an associative array and this is something we can make some with other types of Arabia inside PSP in order to create something that we can understand was in the next example what we do actually talk about multi-dimensional arrays if you want to pull out data from a database like we didn't a couple episodes ago and put it inside an array would actually automatically become an associative array where we get the name of each column inside the database so if you guys want to learn about that you can go back if you episode and see that video on that so this is the basic idea behind associative arrays in the next episode we're going to talk about multi-dimensional arrays so because enjoyed as you guys next time