Hello in this video I am going to discuss arrays. So what is an array? An array is a collection of values a collection of items. So for example, if I have let's say a superhero want I want to list all my favorite superheroes in no particular order equals first uncle Batman. Next I'm going to put Yoda and everybody says to me Yoda, no superheroes. He has powers you know, you don't he's on the good side.
He's a superhero and us Okay, so don't just do one from the Marvel verse. Opera I'm more of an antihero so dead cool. So okay, that's pretty cool. These are you know, common values like to do. Let's say these are my top three favorite superheroes. Deadpool definitely will not make it my top 10 but for the students Something from Marvel and Deadpool popped into my head, but you might have these are my top favorite superheroes.
And yeah, I could have quite as many variables on that one. And Nova way that you can do this is by creating an array. So the beauty of using an array is you just have the one variable, and it sort of has sections inside of it. So to create it, we call we just name it, and the naming convention is the same variables. So feel free to check out that video if you forgot, and I'm going to call the super hero array equals and then you put the keyword array. Then in here is where you specify the value.
So for Batman, then to specify the next value, you put a comma, and the values don't have to be strings, they could be number they could be any data type that is fine. And then I specify Yoda and then I specify dead And as you can see, if I want to add in the one easy, I'll just put comma, and then on finals, if not zero, Bob added him in there anyway. Whereas with this, I would have to create another variable, then do the assignment where this is added on to the end. So how do we know no ecoli? Sir. So what happens for just echo out array like so let's see array to string conversion.
Well, it's not really an era, it's basically saying it doesn't know what to do with that. So to actually access a particular value, you put square brackets, and then the value you want to access in terms of a number. So this is the first index second, third and fourth index. So what if I put one I put one here. I put one there, we get Yoda, even on the first one Batman and the reason is pretty much everything in computing Always started as the rope. So if you want to access the first element in the array, put zero.
And before we load that we get Batman. So to access a particular element, you find the position. And if this is in the third position, you take away one, so it's always n minus one. So if that's the first position to access it to, and there we go, I could assign this to another variable, I could pass it into a function, which you'll learn later on in this series. I could store in the database, anything that you want. So that's really it for an array.
If you want to know the size of the array, you can do that in column B. So by doing echo count, then you put for the array names, so superhero array, and then it says I saw your false that means there are also elements which Dell 123 and the final fourth element for That's really for a ray. And anything else that you should know? Nope. That is it actually a few other things. But I'm going to have separate videos coming that I'm going to talk about associative arrays, multi dimensional arrays, and a bit later on in the series.
Once I've actually covered, you know, control structures and doing loops, I'm going to cover how to essentially, you know, get every single value from the array. Easily instead of having to do dollar superhero array, zero dollar superhero array $1 superhero Ray to that can get tedious if you have three, four or five elements, not too bad. But imagine if he had 1000 elements like us getting, you know, some information on database, it's not practical, you can't really type that out. And plus, you might not know how big the array is going to be. What do you do then? So again, that's going to be covered a little later in this series.
So look forward to that. I look forward actually forgot any questions, drop me a message. And as usual, I look forward to seeing you in the next video.