Home > Backend Development > PHP Tutorial > PHP Tips: Function Overloading_PHP Tutorial

PHP Tips: Function Overloading_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:29:04
Original
822 people have browsed it

1. You can use the two functions func_get_args() and func_num_args() to implement function overloading!!

PHP code:

Copy code The code is as follows:

function rewrite() {
$args = func_get_args();
if(func_num_args() == 1) {
func1($args[0]);
} else if(func_num_args() == 2) {
fun c2($args[0], $args [1]);
                                                                {
echo $arg1, ' ', $arg2;
}
rewrite('PHP'); //Call func1
rewrite('PHP','China'); //Call func2



2. Use the default value to get the results you want based on the input:

Copy code

The code is as follows:

function test($name="Xiao Li",$age="23") { echo $name." ".$age; } }
test();
echo "
";
test("a") ;
echo "
";
test("a","b");





http://www.bkjia.com/PHPjc/779164.htmlwww.bkjia.com

truehttp: //www.bkjia.com/PHPjc/779164.htmlTechArticle1. You can use the two functions func_get_args() and func_num_args() to implement function overloading!! PHP code : Copy the code as follows: function rewrite() { $args = func_get_args(); if(func_...
Related labels:
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