Placeholder Image

字幕列表 影片播放

  • So let's talk about multi dimensional A raise now.

  • Multidimensional raise really are not as complicated as most people think when you start dealing with multi dimensional raise.

  • This is the first point where really people start feeling as if their brains are going to start melting.

  • But it's actually a rather simple concept.

  • As long as you sit down breathing, breathe out and just really think about what you're Cody and really thinking about what you're doing.

  • So as I've talked about before, what an array is, it's essentially, it's a variable with multiple values of different positions.

  • So let's say you're going to create a list of names you'd have dollar sign names, equals array and then Bob, Suit Tim, Fred, so on and so forth.

  • What if you won't be able to contain Maur information within an array?

  • So basically, the idea of an array really is a wayto compartmentalized information or data so you can keep it in one space again when you start coding.

  • One of the issues that you're going to run into is just being able to mentally keep track of everything going on and then being able to code in a simplistic away as possible in order to access the data that you need again.

  • That's one reason that you would use an array versus simply having a whole bunch of variables, you know instead of having dollar sign.

  • Name $1 sign.

  • Name $2 sign named $3 sign named four.

  • So on and so forth.

  • You can create an array simply of names and then have all those values without that array, right that makes life a lot easier.

  • Well, the same is true with a multi dimensional array of what if you want to be able to contain a raise within an array to make it easier to access.

  • So one of the things eso won the demonstration that I'm going to be showing you is basically where we have an array of clothing types.

  • But within that array of clothing types, we have tops and so tops is long sleeve T shirt, sweater, and then we have bottoms, pants, shorts, skirt.

  • So the idea is that we have one array to contain the different types of clothing that we have, but then, within that array we have different other or raise in order to be a bit sort the different types.

  • So we have tops.

  • We have bottoms, we can have all different types of things, and so this makes it a lot easier when we're coding.

  • So instead of trying to remember the exact variable name or so on and so forth, we can simply access the types array.

  • And then we can access keys within the multidimensional array that we've created.

  • So with that, let's go over to the computer to try toe to show you this, and I think it'll make a little bit more sense.

  • So this is a simple script for a multidimensional of Ray.

  • Please realize that multidimensional rays can get ridiculous.

  • I'm not sure if there's a real limit for how many a raise you can put within an array.

  • I literally heard of one coder who created a nine level, multidimensional array simply to make it so complicated.

  • Understand that he had complete job security because nobody else could understand how complex he had made the array.

  • So when you're looking at these arrays and when you're looking at multidimensional arrays, you do want to balance the ease of use and making your life simpler for being able to keep track of information by turning the infanta the data into a raise versus making it too complex to the point that it gets too confusing for people to understand.

  • This is one of those things you're just gonna have to be thinking about.

  • There's no real rules to this.

  • You have to figure out what makes sense and what actually makes life easier versus makes life more complicated.

  • So basically, what we've done here is we've created three a raise.

  • So the top array, basically the array that will have a raise in it is going to be this types.

  • So we have dollar sign types and we're going to set this.

  • We're going to create an array, and then what we're going to do here is we're going to put these other two are rays into the types array.

  • So what we've done is for this array, we put the name key of top, so name, key of top.

  • Then we're going to set that to the value of dollar signs shirts.

  • This is a different array, so top the named key will be set to the array of shirts they were gonna do comma.

  • They were going to say bottom is going to be set to the value of the array bottoms.

  • So the bottoms here now we've created these two arrays and so basically these air different values for the different types of clothing.

  • So for dollar signs, shirts were going to equal array.

  • And this is simply gonna be an unnamed array.

  • That's just simply when I created you could make this a name to Ray or not.

  • And all we've done here is in this array.

  • We've created a value, a long sleeve.

  • We've created the Value T shirt and we've created a value sweater.

  • So for shirts, we have these three types of shirts.

  • Then we have bottoms, we equal, we create the array.

  • And so bottom's We have pants, we have shorts and we have skirt.

  • So these are the different options within bottoms.

  • And then what we do here and then again, as I said, is types, this is the top array.

  • We're going to set this to the value we're going to do the name key of top.

  • We're going to set that value to the shirts array.

  • Then we're going to keep create the name key of bottom and set that value to the bottoms array.

  • So now this these are two are rays that are now within the types array.

  • Now, in order to be able to access a multidimensional array what Weaken Dio as we come down here and we're simply going to use the print Command to show you how to access this.

  • But you could you could set a variable to one of the values that comes out.

  • You could to be do loops.

  • You could do a lot of different things again.

  • You're now accessing the values within this multidimensional array.

  • That's what we're gonna do is there s a print double quotation marks and we're doing a print.

  • And now with this, when we're accessing the values in a multi dimensional array, what we're going to do is we're going to contain it within the squiggly brackets were going to open up a squiggly bracket.

  • You're going to say dollar sign types.

  • So this is the array dollar sign types.

  • Then we're going to a bracket.

  • So the first array, they were doing single quotation mark top.

  • So what we're doing here is for the array types.

  • We're going to open up the top key within it that has that has the array.

  • And then what we're going to say is from top.

  • So basically from shirts here, what we want is the value that's residing in space number two.

  • Now, do you remember with the arrays it starts at zero.

  • So when I say I went from top space number two, so top comes here.

  • So we're looking at the array shirts, So this is the array.

  • So when we're looking for space number two, we don't want T shirts because T shirt is actually space number one long sleeve ups.

  • Long sleeve is zero T shirt is one, and then sweater is too.

  • So that is one thing to remember with an array, especially when you're doing it this way.

  • And so basically, what they should do is they should print too.

  • So basically, this should print sweater if everything works properly.

  • So if we go over, I got a silicon Dozo multidimensional array.

  • Yeah, and now we've printed sweater.

  • So we were able to access the value in shirts that was within types.

  • So this is what a multidimensional array looks like.

  • And again, you could use this thing with like inventory control systems or other ways.

  • We're basically, let's say again, like clothing types.

  • So he won an array of clothing, but within clothing we're gonna have multiple types of clothing.

  • So this is a way to categorize those different types and make it be able to be easier to access and deal with that information when you go to write more complicated scripts.

  • So that's what we're talking about when we're talking about multidimensional arrays, we're talking about a raise within a raise that may possibly be within a raise.

  • Well, which may be in even Maura raise.

  • This is one of those.

  • This is one of those concepts and coding that once you understand, it could make your life easier.

  • But at first it could be difficult to comprehend.

  • And again, sometimes people take this a little bit too far.

  • And so one thing that you have to think about is what, using multidimensional arrays, what makes your life easier and what actually makes your life harder.

  • And then again, just figuring out where that balances.

So let's talk about multi dimensional A raise now.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

PHP - 多元數組 (PHP - Multidimensional Arrays)

  • 6 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字