Home > Backend Development > PHP Tutorial > A small example of how to specify a default value for a php function_PHP Tutorial

A small example of how to specify a default value for a php function_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:18:14
Original
1004 people have browsed it

Content of this section:
Specify default values ​​for PHP functions
In PHP programming, set default values ​​for custom functions. When the user calls the function, if no value is specified for the parameters, the parameters will use the default values. Value replacement.
Example 1,

Copy code The code is as follows:



php function specifies the default value-www.jb51.net


function printMe($ param = NULL)
{
print $param;
}
printMe("This is test");
printMe();
?>


Output result:
This is test
Example 2, example of using default values ​​of php function parameters, setting and using default values ​​in php function parameters.
Code:

Copy code The code is as follows:



php function parameter default value - www.jb51.net


function textonweb ($content , $fontsize=3){
echo "$content";
}
textonweb ("A
", 7);
textonweb ("AA.
");
textonweb ("AAA.
");
textonweb ("AAAA!
") ;
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621698.htmlTechArticleContents in this section: Specify default values ​​for php functions In php programming, set default values ​​for custom functions. When the user calls this function, if no value is specified for the parameter, the parameter will be replaced with the default value...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template