‫All right, so now that you know how to create functions, let's create some functions that are actually
‫useful as opposed to add functions and say hello.
‫So we have this jobless things that we've been working on.
‫And it's the same thing that we left off with.
‫We have our array we have for each going through all the listings.
‫And we have a couple conditionals here, like this ternary to see if we're on an even number for the
‫card.
‫And then we add a big blue class.
‫If it is big, white if it's not.
‫So I want to do a couple of things here.
‫One, the salary isn't formatted very well.
‫It's just a straight number.
‫There's no commas, there's no dollar sign or anything like that.
‫So that's what I want to do.
‫First is create a format salary function.
‫And if you want to pause the video and try this stuff on your own, you're more than welcome to do that.
‫I would actually recommend doing stuff like that, but I'm just going to go up here to the top under
‫the array.
‫But still within the PHP tags.
‫And we're going to call this format salary.
‫And let's pass in a variable of salary.
‫And all I'm going to do here is return that that number that's being passed in.
‫But I first of all want to put a dollar sign in front of it.
‫And then I'm going to concatenate on the number format function, which will take care of the commas
‫for me where they're supposed to go in terms of the thousands.
‫And this is kind of a new function.
‫Before this, we had to create our own function using like regular expressions and stuff like that.
‫But this makes it really easy.
‫So let's return that.
‫Let's pass in salary, which is going to be the number we want to format.
‫And I'm also going to put in two here, which is the the number of of decimals that I want.
‫So to use this we're just going to come down where we're outputting the salary which is right here.
‫And we're going to wrap this in format salary.
‫So we just want to wrap that job salary.
‫And if I reload now you'll see that the salary is formatted much better actually.
‫You know what I think decimals might not make sense here.
‫It's not like we're going to put change on there.
‫So maybe we can get rid of that too.
‫And that will get rid of the decimals.
‫All right.
‫Cool.
‫So the next thing I want to do is for the tags I want to be able to highlight certain tags if we want.
‫So we'll have a function called highlight tags.
‫We'll pass them in and then pass in some kind of search term like let's say we want to highlight all
‫the tags of development or accounting or whatever it might be.
‫So let's come up here and let's say function.
‫Highlight tags.
‫And that's going to take in two things.
‫It's going to take in the tags themselves.
‫And then it's going to take in the search term or basically the tag that we want to highlight.
‫And let's create a variable here.
‫We'll call this tags string and set that to implode because.
‫If we come down here to where we're showing the tags, we're doing the implode here.
‫Right.
‫So this is an array jobs tags.
‫And what we're doing is turning it into a string and separating each array item or each tag with, with
‫a comma and a space.
‫That's what this is doing.
‫Instead of doing that here I want to do it in the function.
‫So we're going to say implode.
‫Same thing we're going to do comma space.
‫And then we want to add tags.
‫So that will give us the string.
‫All right then I want to.
‫Basically just replace the whatever the search term we look for.
‫So let's say let's say accounting, right.
‫We want to look for that.
‫And we want to replace it with that same tag, but we want to wrap it in a span that has a big yellow
‫200 class.
‫So we're going to use a function called str replace or string replace.
‫So let's say return.
‫So we want to return from this function str underscore replace.
‫And we want to find the search term.
‫Yeah.
‫Whatever we pass in, we want to replace that with.
‫I'm just going to use double quotes here and say span class equals.
‫And then in single quotes let's do BG dash yellow dash 200.
‫Of course if you want to change the color you can.
‫And then we're going to have let's do our ending span.
‫And inside that span we want to have our search term.
‫Actually I'm going to use.
‫Curly braces here.
‫Let's say search term.
‫Okay.
‫And then the last thing we want to pass in here let's put another comma.
‫And that's going to be the tags string.
‫All right.
‫So again it's going to it's going to look at the tag string which is this.
‫Right.
‫The comma separated values.
‫And it's going to look for whatever is passed in as the search term.
‫Let's say accounting is passed in.
‫It's going to replace that with that search term.
‫Say it's accounting with this span around it so that it has that yellow background that looks like it's
‫like highlighted.
‫All right.
‫Then we can just use that down here.
‫So instead of doing the whole implode since we're doing that in the function we can get rid of that.
‫And we can just call highlight tags and we can pass in our job tags.
‫Um, yeah, we should be able to do that, right?
‫Highlight tags.
‫What am I missing here?
‫Expected two arguments.
‫Oh yeah.
‫We need to pass in a term.
‫So let's say we want.
‫What do we have here?
‫Looks like it doesn't look like any of these.
‫Really.
‫Repeat.
‫Let's let's add a tag that repeats.
‫So, counting.
‫Let's see.
‫SEO, let's take SEO.
‫Let's put that on the first one as well.
‫So we'll say SEO and we'll use that as, as what we want to highlight.
‫So then back down here let's pass in as a second argument SEO.
‫So if we save that and we come over here and reload, now you'll see that SEO, wherever that shows
‫up on any listing, it's going to be highlighted.
‫And of course you could change that to whatever you want.
‫Not not a huge like feature, I guess, but it's just an example.
‫You know, we're learning about functions and it's it's a helper function.
‫So in the next video we're going to do a little challenge.
‫And I want you guys to try to get the average of these salaries and put it at the top.