After several months of trying to get my head around PHP frameworks, moving from one to another with basic php knowledge I decided to call it a day with frameworks and go back to the php books and learn from scratch so in future in the near future I can start building my website mvc style without having to learn some other framework that would be abandoned when a newer version came out.
Anyway I purchased Learn PHP, MySQL and Javascript book by Oriely Media and have been practising and find it very interesting.
HOWEVER…
I am trying to get my head around this:
<?php
echo name_fixer("WILLIAM", "henry", "gAtEs");
function name_fixer($name1, $name2, $name3) {
$name1 = ucfirst(strtolower($name1));
$name2 = ucfirst(strtolower($name2));
$name3 = ucfirst(strtolower($name3));
return $name1 . " " . $name2 . " " . $name3;
}
I have an idea what is going on but my question is when the function is called/echoed are the names I’m passing as arguments being passed into the function?
I would like to know exactly what is going on. For some reason this is the only part of the book so far where the writer hasn’t gone into detail about exactly what is happening.
A thorough explanation would be appreciated greatly and allow me to move on to the next part of the book.
Yes, the names you are passing as arguments get passed into the function.
The idea is that you pass values to the function and then those values are put into the variables you specify in the function’s declaration of arguments.
You can call your argument variables anything you want, so they don’t have to be
$argument1or whatever. They are assigned values in the same order as what was passed, so ‘a’ gets assigned to $argument1, and ‘b’ gets assigned to $argument2.There’s a lot more to it than that, like passing more than just a single value (you can also pass things like arrays and objects), and you can also pass by reference, etc.. but you should get to that in your books. The overall point here though is that you pass a value to the function and the variables specified in the argument area receives those values, so that the function can do stuff with them.