Concept

How do default parameter values work in PHP functions?

ComputerScienceOne / Optional & Default Parameters

"PHP also allows you to define alternative default values for function parameters. Consider the following example.\n\nfunction getMonthlyPayment($principle, $apr = 0.05, $terms = 60) {\n\n$rate = ($apr / 12);\n\n$mp = (($principle * $rate) / (1-pow(1+$rate, -$terms)));\n\nreturn round($mp * 100) / 100;\n\n}\n\nIn this example, the second and third parameter have been given default values of 0.05 and 60 respectively. If a call to this function omits these parameters, they are not treated as null, but take on these defaults instead.\n\n$x = getMonthlyPayment(10000, 0.07, 72);\n\nprint $x; //170.49\n\n// terms will be 60\n\n$x = getMonthlyPayment(10000, 0.07);"

Related Ideas

How do default parameter values work in PHP functions? | ComputerScienceOne | Bifalgorithm | Bifalgorithm