So far, we've been passing the arguments to functions by having to remember about the order of every
single argument.
So in this video, we're going to learn about the named arguments.
That's the most recent PHP feature introduced in PHP 8.0.
And it basically lets you pass the arguments by specifying the argument name argument value combination
instead of having to remember about the order.
So let's create an example a grid function with a name with the greeting, which can have a default
value, and whether someone should shout, which also has a default value.
And this all returns a string.
Okay, so now let's just create a message based on greeting and the name.
And we're going to return that whether we need to shout.
We use the ternary operator.
So if this is true then we return the option on the right which would be str are two upper, so we uppercase
the message or after the column.
If the shout is false.
This would be returned and that would just be the original message.
Now let's see an example of this with positional arguments.
So I can greet Alice.
Maybe let's concatenate this with a new line.
Then another example can be saying hi to Alice, and yet another example can be saying hey and saying
that someone should shout.
So obviously this works and it's perfectly fine.
But the problem maybe I need to go to the functions folder, but the only problem is that you really
need to remember the order of arguments.
And while this generally is a good practice to create functions that do not have a lot of arguments,
if you have ten arguments, you are probably doing something wrong and should separate that into couple
Functions.
Anyway, it is hard to remember the order of functions.
And let's see how can we do that with named arguments instead?
So I'm doing grid function call, and now I can set the name to David.
And I can set that David.
Or the welcome message to David should be shouted.
So when I now run named PHP, as you see, this works perfectly fine.
But now I don't have to worry about the position of arguments, which also lets me ignore the arguments
that have default value.
Otherwise, um, I would have to provide the value for the second argument, even though it has the
default value, and I might want to use the default one.
And that's the case with positional arguments to provide the value for the third argument, you can't
skip the second one.
And with named arguments this is possible.
And I also think this is much easier to remember.