Placeholder Image

字幕表 動画を再生する

  • So let's talk about creating a raise and PHP.

  • So essentially all it array is is an array is a variable with multiple values, so it has indexes.

  • So index 0123456789 10 So on and so forth and into those index lots, you can put different values.

  • So why this could be valuable is if you're going to be doing something, let's say you're having a party or you're having an event and multiple people will be coming to your event and you want to be a little list out who those people are in alphabetical order.

  • Now, if you were using basic variables in order to add all those names and individual variables and then B of a sort that and printed out, it would be a complicated process.

  • If you use an array, what you do is you can create the array put in Bob and spot zero Marion's spot.

  • One.

  • Put in all of these different names, then what you could do is you can do a sort on that array either alphabetically or reverse alphabetically, and then you can print out the results of that sort.

  • So It makes life a lot easier when you're going to be doing things like if you have a large list or the other thing that you could do is if you're going to be collecting a number of bits of information about a certain sum, let's say a certain person.

  • So let's say you want to use information about a person because you're using some kind of contact relationship management software.

  • So what you could do is you could put dollar sign person or dollar side user and turn that into an array and spot.

  • One could be their first name spot to could be their last name.

  • Their email address, their phone numbers so on and so forth.

  • So you can have all of that information, essentially in the equivalent of one variable.

  • And so then you could just do dollar sign person and then go to the key for whatever information you're trying to get, whether it's their first name, whether it's their last day, whether it's your email address and be able to pull out the information that way.

  • So the two reasons that you generally use a raises either you're creating a list.

  • So all this information goes into a list so that you can you can order it, you can sort it, or if you're trying to collect a lot of information, a lot of different piece of information, basically essentially about one variable, let's say like a user or something like that.

  • You can plug all this information in, and then you know exactly where to go back to.

  • And so that's really all there is to a raise.

  • So with that, let's go over to the computer so I can show you how to create a ray and how you can print out the values that are in it.

  • Now, as I have talked about before, there are different versions of PHP.

  • So as I do this particular Siri's were a diversion seven point something or other.

  • And in those different versions, there have been different ways to create a raise.

  • So in the later versions of PHP, there's actually a different way to create an array than what I'm showing you now.

  • Why I'm showing you what I'm showing you is because this is ah, backwards compatible.

  • So if you're using PHP seven, this will work.

  • If you're using PHP four, this will work.

  • Whereas if I show you a different way of creating an array, it'll work and pee HB seven.

  • But it won't work.

  • And PHP four.

  • So that is something to realize if you're If you're a coder that knows what's going on.

  • You're wondering why I'm showing this.

  • I'm just showing this for ease so people can get used to it and to realize if you know you're working on a platform that has PHP seven, there is a different way to create a raise that that looks a lot better and is a little bit easier to dio.

  • But this will work regardless.

  • So I created a script right here.

  • The always called is a ray dot PHP and of course, create a script.

  • We start with a PHP tag.

  • Then from here, what we're going to do is we're going to create the array, so this looks a lot like creating and setting the value for variable.

  • So we're gonna do is we're going to create dollar sign names.

  • So this is gonna be like for a list of names again for a party or for event or something like that.

  • We're going to say, do is they were going to say it equals And then we used the array functions of the ray function is going to add all of these names into the array s O.

  • We do parentheses and then do single quotation mark.

  • So we're gonna be doing is the values are between single quotation marks and then you separate by a comma It's a single quotation Mark Bob Close Single quotation mark comma single quotation marks Sue single quotation mark and with a comma.

  • So just remember, basically you end with a comma all the way to the last one And then you close the parentheses And, of course, you finish with the semi colon and this is all you have to do in order to create an array.

  • So this is now created an array of names.

  • Now, one thing that's important, understand is when you're dealing with your Ray right now and you're dealing with the index keys and numeric index keys, it starts with zero.

  • It doesn't start with one.

  • So right as this is now, Bob isn't spot zero sewers and spot one.

  • Ted isn't spot too.

  • Ralph is in spot three.

  • That's one of those confusing things when you're dealing with a basic array.

  • Just remember that it starts at spot zero.

  • It does not start at Spot one now.

  • What we're going to do here is we're just going to print out all the values in the array.

  • So if we use the print, underscore our function and feed it names, what this will do is this will spit out all the values in Honore.

  • This is useful.

  • You know how in many of the examples I will print out the value of what's in the variable just so we make sure that the value in the variables, what we think is the value of the variable again, this is a good troubleshooting route step where, if you do print, underscore, are and then feed it the array.

  • It will print out what's in the array, and you can make sure what's in the array is what you think is in the Aram past that.

  • Then what we're going to do is we're just simply going to do a print and again a break for HTML.

  • So this will break it to a new line in HTML and then to show you how to print from this particular index spot within an array.

  • What we're going to do is run to print dollar sign names They were going to open brackets.

  • This is a bracket Now and then we're going to say spot too close bracket.

  • Semi colon.

  • Now, when I say spot to you, think about this for a second.

  • Whose name do you think we'll print when I say spot, too?

  • If you said Ted, you would be correct.

  • The reason being is Spot zero is Bob.

  • Spot one is Sue, and therefore spot to is Ted.

  • So this is one of the ways that you could be a little bit confused.

  • Here we go to silicon dodo dot com, of course.

  • And then we d'oh array dot PHP And okay, so this is where that print underscore our is.

  • So it shows us that the variable is an array.

  • It shows us, and spot zero is bob spot one.

  • A soup spot to is ted.

  • Spot three is Ralph.

  • So again, this is just here for trouble shooting.

  • Just so you make sure you know what you're looking at.

  • And then under that, as I showed you here, we do print dollar sign names and spot, too.

  • And that then means Ted.

  • So again, Ted is at two important thing to understand their get.

  • If we go back and let's say we just changed that to spot zero to do file save, we upload and then we come back and refresh.

  • Now we see that array as Spot zero is Bob.

  • So that's really all there is a CE faras.

  • The code is concerned for how to create an array, how to print out the information in the array and then how to print from a specific index in that array.

  • So that's all there is to create it in a basic array so you can start working with it and how to print out from an index position within the array again.

  • To be clear, if you're a long term PHP programmer or if you know you're going to you working in the PHP seven World, there is a different way to create a raise.

  • It makes it a little bit simpler, a little bit easier to read.

  • The reason that I'm showing you this particular way is that it should work across the board regardless of what version of PHP that you're using, so that's just one of those things to keep in mind.

  • So that's really all there is to create an array and being able to read out of right out of an array, and that's why it matters.

So let's talk about creating a raise and PHP.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

PHP - 配列の作成 (PHP - Creating Arrays)

  • 7 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語