The php function specifies a small example of the default value method
- 2020-12-05 17:08:13
- OfStack
Contents of this section:
The php function specifies the default value
In php programming, a default value is set for a custom function, and when the user calls the function, if the parameter is not specified, the default value is substituted for the parameter.
Case 1,
<html>
<head>
<title>php The function specifies the default value -www.ofstack.com</title>
</head>
<body>
<?php
function printMe($param = NULL)
{
print $param;
}
printMe("This is test");
printMe();
?>
</body>
</html>
Output results:
This is test
Example 2, php function parameter default use example, php function parameter set and use the default value.
Code:
<html>
<head>
<title>php Default values for function parameters - www.ofstack.com</title>
</head>
<body>
<?php
function textonweb ($content, $fontsize=3){
echo "<font SIZE=$fontsize>$content</font>";
}
textonweb ("A <br />", 7);
textonweb ("AA.<br />");
textonweb ("AAA. <br />");
textonweb ("AAAA! <br />");
?>
</body>
</html>