Functions are really very simple, and your idea to save you keep rewriting the same piece of code is correct. Here's an example of a function in the same file as the code that calls it (this is generally how it is done).
function ChooseHouse($name) {
if($name == "Bulldozer") {
$string = "Your house will be knocked down by a bulldozer";
} elseif($name == "Workman") {
$string = "Your house will be knocked down by a workman";
} else {
$string = "Your house won't be knocked down by anyone!";
}
return $string;
}
DO THIS COMMAND
$house = "Well.... I dunno";
$page = ChooseHouse($house);
echo $page;
DO THIS COMMAND
$house = "Workman";
$page = ChooseHouse($house);
echo $page;
So what's the advantage I here you ask? Well, without a function where I've written $page = and then a call to the function, I would have to instead have rewritten the code. Great little feature!
Hope this explains it. By the way: DO THIS COMMAND isn't anything you need to, I was just saying that some other PHP coding could go here.
Chris