Imagine a situation where you need to calculate the commission of a sale, you are paying your employees 15% commission. You want to display the commission dollar value everywhere. One solution would be to pepper your code with
Code: Select all
echo "Your Commission is: ".($saleValue*.15);
Now, you have that line (or similar) throughout your site, dozens of times and everything is working great. Six months down the road, you want to be a kind boss and increase your commission rate to 17.5% -- You now have to search through all your code to find the places where you calculate the commission and change the values (.15 would become .175)
You'll be doing this dozens of times, maybe even in a few different files in different folders...
If you were to write a function to calculate the commission:
Code: Select all
function calcCommisssion($sales) {
$commission = .15; // 15%
return $sales*$commission;
}
And use it like so:
Code: Select all
echo "Your Commission is: ".calcCommission($saleValue);
Then, 6 months down the line, you just make a single change in the calcCommission function, and the changes are reflected everywhere you use that function.
Trust us, you will not succeed in programming your game (which you yourself admitted will be BIG) without the use of functions, I'll lay my reputation (assuming I have one

) on the line...