‫Okay.
‫So we have a couple challenges to do here.
‫And these are pretty simple.
‫Remember when I do a challenge in this course it has to only include things we've already gone over.
‫If I do anything new it'll be after the fact when I'm just to show you something.
‫All right.
‫So.
‫And if you don't get them, don't worry about it.
‫Challenges can be tough for some people, including myself.
‫So just don't worry about it.
‫And even if you don't want to try it on your own, that's fine.
‫But I would suggest you do, and I would suggest you try and do it without having to go back and look.
‫Although if you need to go back, that's fine.
‫That's real life.
‫When you're coding in real life, you're allowed to do research.
‫So the first one here is some of an array.
‫And I put everything into steps.
‫So the first step is to create an array of numbers.
‫Pretty simple.
‫Get the sum of all those numbers combined and put it into a variable.
‫Get the amount of numbers in the array and put it into a variable, and then print out the sum of the
‫amount numbers is whatever the sum is.
‫So if it's an array of one, two, three, four, five, then the output should be.
‫The sum of the five numbers is 15.
‫All right.
‫So let's go down here I just echoed out some headings just to kind of separate things.
‫So the first thing is to create an array of numbers.
‫So let's do that let's say numbers.
‫And I'll just use 12345.
‫You can put any numbers you want though any amount that you want.
‫And then we want to get the sum of those numbers combined.
‫And there's a few ways we could do this.
‫So.
‫The first way is to use some array which is a function.
‫So let's say sum equals I'm sorry array sum not sum array.
‫So array sum and then pass in the array which is numbers.
‫And just to kind of check that out let's echo out sum.
‫Reload and we get 15.
‫Now, if you wanted to do it kind of the long way without using array sum.
‫You could say sum equals and then numbers get the first item.
‫Add onto that.
‫Let's just grab this.
‫Okay, so you'd add on to that numbers.
‫One add on to that number is to.
‫Numbers three.
‫And numbers four.
‫Okay, so that's all five.
‫And then if I save that, we should still get 15.
‫All right either way.
‫So the next one next step is to get the amount of numbers in the array and put that into a variable.
‫So let's create a variable called amount.
‫And let's set that to.
‫Remember we have the count function.
‫So we just need to pass in.
‫The numbers.
‫And then let's echo out.
‫Amount.
‫And we get five.
‫Okay.
‫If I were to put.
‫Six in there.
‫Then I'd get six.
‫Okay, so the next step is to print out the sum of and then whatever the amount numbers is the sum.
‫So let's do that.
‫Let's echo.
‫And I'm going to use single quotes here.
‫If you want to use double quotes, that's fine.
‫Double quotes is a little easier because you don't have to do the concatenate.
‫So let's say the sum of the and then space.
‫And then I'm going to concatenate onto that.
‫The amount and then go back into a string and say numbers is space, and then concatenate onto that
‫the sum.
‫So let's go ahead and reload and we get the sum of the five numbers is 15.
‫All right.
‫So pretty simple challenge.
‫So next we have colors array.
‫So it provides us with an array of colors.
‫So first off we want to reverse the colors array.
‫We want to add purple and orange to the end of the array.
‫We want to replace the second color with pink and then remove the last element of the array.
‫And we should end up with this.
‫Yellow.
‫Pink.
‫Blue.
‫Red.
‫Purple.
‫All right.
‫So first step is to reverse the array.
‫So I'm just going to put it back into the variable colors and set that to array underscore reverse.
‫Colors and then just to kind of show.
‫That that worked.
‫Okay.
‫So now we have yellow green blue red.
‫So that's the first step.
‫Next we want to add purple and orange to the end of the array.
‫So let's go under where we defined the reverse array.
‫And we're going to use array push.
‫Now array push doesn't return the array with the new item.
‫It just manipulates the current one.
‫So we don't have to set a variable or anything like that.
‫We just say array not array reverse array push.
‫And let's add let's say colors, and we want to add on to that.
‫Purple.
‫Okay.
‫And then we can also add add a new item to an array just by taking the array colors and then empty brackets
‫and then set that let's say orange.
‫So both of these do the same thing.
‫They just add a value.
‫So let's save and reload.
‫And now we should see purple and orange on the end.
‫And I'm going to show you another way that we can do this using array merge.
‫And I don't think I went over array merge but it does just that.
‫It merges arrays together.
‫So let's say using array merge.
‫So what I want to do is set the colors because array merge will actually return a new array.
‫So let's set that.
‫And for this to work I'm going to have to just comment out what I did here.
‫Yeah comment out these two.
‫So we're back to just yellow green blue red.
‫So I want to add purple and orange.
‫So what I could do is say array.
‫Merge and I can pass two arrays in here, the first one being colors, and then the second.
‫I'll just create an array here with purple.
‫An orange.
‫Okay, so I'll save that.
‫We'll reload and we get purple and orange added to the end.
‫So these two lines are doing the same thing that this line is doing.
‫And there's many other ways you could do this as well.
‫All right.
‫So now the next step is to let's see replace the second color with pink.
‫So right now the second color is green.
‫So we want to replace that with pink.
‫So what I'm going to do is use array splice.
‫So let's say array.
‫Underscore.
‫Splice.
‫And we went over this in the array methods lesson.
‫So it's going to take in the array.
‫And then it's going to take in where we want to start okay.
‫And array splice.
‫You can use it to just replace something.
‫So I want to start at one because it says the second color which would be the index of one.
‫And I only want it to be that one.
‫So I'm going to pass in one for the offset.
‫And then the value that I want to put there which is pink.
‫All right, so now when I reload, green should change to pink.
‫There we go.
‫And then the last step is to remove the last element of the array.
‫And we can do that using pop.
‫So let's say array underscore pop.
‫Colors.
‫Reload when I should go away when I reload.
‫And now let's see if we get the same as the result.
‫We have.
‫Yellow.
‫Pink.
‫Blue.
‫Red.
‫Purple.
‫All right.
‫And I'm just going to comment out that print.
‫All right.
‫Cool.
‫So that's the second one.
‫The last one is to create a multi dimensional array of associative arrays of three job listings.
‫And the job should have the fields ID, job title, company contact email and contact phone.
‫Also add an array field for skills.
‫The skills array should be an array of strings with each skill a person has for example PHP, MySQL,
‫JavaScript, HTML, etcetera.
‫So that's the first step is to create that array.
‫Why don't we do that before we do anything.
‫So we'll come down here and let's create a variable called listings.
‫Set it to an array.
‫And inside here we're going to have an associative array or a few associative arrays.
‫And the fields which are going to be ID.
‫So let's set that to one.
‫What else?
‫Job title.
‫So let's set that to PHP developer.
‫Then we have.
‫What was the other one?
‫Um, job title company.
‫So company.
‫Let's set that to ABC company and then we have contact email.
‫Set that to John.
‫And it doesn't matter what you use for values.
‫Contact underscore.
‫Phone.
‫Set that to one, two, three.
‫All right contact phone and then skills which should be an array.
‫So let's say skills set that to an array let's say PHP.
‫Uh, MySQL or MySQL.
‫A lot of people get mad when I say when I spell out SQL and JavaScript.
‫All right, so there's one.
‫It says to have three of these.
‫So what I'm going to do is grab this, we'll have a comma.
‫Another comma.
‫Paste that in and then just change up a few things.
‫So the id let's change the.
‫This will say web designer.
‫Change that to one, two, three company.
‫We'll say, Jane.
‫Phone number.
‫And let's change this up, we'll say.
‫A Photoshop.
‫Illustrator.
‫And CSS.
‫I spell that wrong.
‫Photoshop.
‫Okay.
‫And then this one here.
‫Let's do.
‫We'll just say web developer.
‫And for company, we'll just we'll keep ABC company.
‫We'll keep the rest.
‫Doesn't really matter.
‫Just change the ID to three.
‫Okay.
‫So now we have our array of associative arrays.
‫So let's see what the next one is.
‫Create a new listing.
‫Actually let's just print this out real quick.
‫So print our.
‫Listings.
‫Okay, so the next step is to create a new listing using the array push function.
‫The new listing should have the same fields as the others, so that's pretty simple.
‫We can just.
‫Grab one of these.
‫Array push.
‫Again, this just manipulates the current array.
‫We don't have to put it into a variable or anything.
‫We're not returning anything.
‫So let's say for.
‫Graphic designer.
‫And I'll just grab.
‫This.
‫Okay, so if I save that reload, we should see.
‫Um.
‫What's going on here?
‫Print our array.
‫Push.
‫Oh, I didn't put the the name of the.
‫Array.
‫So.
‫Listings.
‫I'm so used to JavaScript using dot push.
‫So now you can see graphic designer has been added.
‫So the next one is to print out the job title of the second job listing in the array.
‫So the second job listing is web developer.
‫That's the job title.
‫So we want to print that out.
‫So let's comment out the print R and let's echo.
‫Listings.
‫And then we want the second listing.
‫So the one index.
‫And then we want the job title.
‫And we get oh, did I say.
‫Yeah, it's a second listing.
‫Print out the job title of the second job listing.
‫Which is webdesigner.
‫Okay.
‫All right.
‫So lastly we have print out the first skill of the third job in the array.
‫So the third job is web developer.
‫And we want the say first skill.
‫Yeah first skill which is PHP.
‫So let's echo out listings.
‫We want the third job, which is going to be to.
‫Um.
‫And then we want.
‫Skills.
‫Skills which is an array.
‫And we want the first item in that which would be zero index which should give us PHP.
‫Let's comment this this out.
‫Reload and we get PHP.
‫All right.
‫So that's pretty much it.
‫If you didn't get it, that's absolutely fine.
‫Don't worry about it if it was too easy.
‫Sorry about that.
‫But we have to accommodate, you know, every, every skill level.
‫But that's it.
‫In the next video we're going to start to look at loops and iteration.