‫Okay, guys.
‫So I didn't label this as a challenge, but I'd like you to to try it as a challenge because it's pretty
‫much the same thing that we did in the last video, using a for each loop to loop over some items in
‫an array or some associative arrays and output some data.
‫So this is the starter file you can get in the sandbox starter.
‫It just has some listings in an array I think five different listings.
‫And then we have some HTML and this is all hard coded right.
‫So the two jobs you see here, software engineer, marketing specialists, these are just HTML hard
‫coded right.
‫We have the title description and so on.
‫What I'd like you to do is make this dynamic by outputting one of these job cards for each of these
‫array items.
‫So you'd have to wrap certain HTML, whatever this card is in a for each loop.
‫And then add in your fields, you know, add in your your job title job description, whatever these
‫fields are.
‫So if you want to pause the video, try it on your own.
‫You can do that.
‫If not, just follow along.
‫So we have two cards here, right?
‫Well we only need to wrap one in the for each loop.
‫So let's figure out what we need to wrap.
‫So we have this div with the class of MD and m y for.
‫That ends.
‫I believe that ends, right?
‫Yep.
‫Ends right here.
‫Then we have the second one.
‫So that wraps everything in the card.
‫So we don't need the second one.
‫So that ends here I'm going to grab that get rid of it.
‫Okay, so we know that this div with the class of MD my four.
‫In fact I can show you over here to.
‫So this.
‫Yeah, this right here.
‫Right.
‫That's what we want in our for each loop.
‫And we want dynamic values rather than hardcoded.
‫So let's wrap that.
‫So PHP for each.
‫And then listings is the name of the array.
‫And we're going to say as.
‫We could do listing or let's just do job, okay.
‫And then we need to end that for each after this divs ending tag, which is right here.
‫So now we'll do PHP end for each.
‫Now, if I go ahead and save that and reload, what's going to happen is I'm going to see five of these
‫because I have five items in my array.
‫However, it's all the same content because it's hard coded.
‫So all we need to do is replace this with dynamic data so that we know that this is the title.
‫Right.
‫So we can say job.
‫And then title.
‫So now if I save that reload.
‫Now notice all the titles are different.
‫They're coming from that array.
‫And normally in a real application this will come from a database.
‫But right now it's just a hardcoded array.
‫We'll get to the database stuff later.
‫So I'll just copy this.
‫And we know that this right here this longer text.
‫This is the description.
‫Okay.
‫Then we have the salary.
‫So I'm going to replace that.
‫With job.
‫Salary.
‫Okay, now it doesn't have a comma.
‫We're actually going to when we get to functions we're going to create some helper functions to format
‫the salary location.
‫Let's swap that out with job.
‫Location.
‫Okay, now we have all different locations and then we have tags.
‫So let's replace that.
‫With job tags.
‫Actually.
‫Wait a minute.
‫What did we do for tags?
‫Okay, so for tags we have an array.
‫So I can't echo out an array.
‫So remember that implode function.
‫It turns an array into a string.
‫So we're going to use that here because we don't have to just output straight variables.
‫We can use functions and expressions and so on.
‫So I'm going to say implode.
‫And I want to between the items in the array, I want to have a comma and a space.
‫That's the first argument.
‫The second is the actual tags, which is in jobs.
‫And then tags.
‫Save that reload.
‫Sorry.
‫It's job tags.
‫And there we go.
‫So now, whatever we have in the arrays up here like this first one software development Java.
‫Python is now a comma separated value list.
‫Now a string because we used implode.
‫All right.
‫So and if you didn't get that, don't don't worry about it.
‫But in the next video we are going to do a couple smaller challenges that have to do with arrays and
‫loops.