The problem of the form participation argument of function in PHP _php skill

Source: Internet
Author: User
PHP warns when the number of arguments < The number of parameters, because the interpretation mechanism of PHP will assume that the parameter is defined and not used, it is likely to affect the function of functions. So a warning is issued. However, when the number of arguments > The number of parameters, PHP is not an error, it will only take a few previous parameters, the extra will be discarded.

To write a function in PHP, when calling a function in general, the changed value is a formal parameter instead of an argument. But if you add an address character to a formal parameter, you change the value of the argument, why?

Take a look at the following example:
Copy Code code as follows:

<?php
Write a function swap () to test that the function's argument value does not change
function swap ($a, $b) {
echo "<p> enter SWQP () function before <br>\n";
echo "before Exchange: formal parameter a= $a, formal parameter b= $b <br>\n";
$c = $b;
$a = $b;
$b = $c;
After echo Exchange: Formal parameter a= $a, formal parameter b= $b <br>\n ";
echo "Exits the Swap () function <br></p>\n";
}
$variablea = 5;
$variableb = 10;
echo "Before calling the Swap () function:";
echo "Real parameter a= $variablea, the actual parameter b= $variableb <br>\n";
Swap ($variablea, $variableb);
Echo calls the swap () function: ";
echo "Real parameter a= $variablea, the actual parameter b= $variableb <br>\n";
?>

Copy Code code as follows:

<?php
To test the value of a swap () function argument
Function Swap1 (& $a,& $b) {
echo "<p> enter Swap1 () function <br>\n";
echo "before Exchange: formal parameter a= $a, formal parameter b= $b <br>\n";
$c = $b;
$a = $b;
$b = $c;
After echo Exchange: Formal parameter a= $a, formal parameter b= $b <br>\n ";
echo "Exits the Swap () function <br></p>\n";
}

$variablea = 5;
$variableb = 10;
echo "Before calling the Swap1 () function:";
echo "Real parameter a= $variablea, the actual parameter b= $variableb <br>\n";
Swap1 ($variablea, $variableb);
echo "calls the Swap1 () function:";
echo "Real parameter a= $variablea, the actual parameter b= $variableb <br>\n";
?>

The above two examples is the explanation, has consulted ~ ~ ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.