When a function with arguments is called, the values for the arguments are passed. If they are omitted, you get an error. So to avoid this issue, you can give function arguments a default value that is used if you don't supplie a value.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php function Add($num1, $num2 = "3") { echo "$num1 + $num2 = ", $num1+$num2, "<br />"; } Add(); Add(2); Add(2, 5); ?> </p> </body> </html> |