php--Custom Functions

Source: Internet
Author: User

<?PHP//define a function with a default value functionMain3 ($f=5,$g=6) {     Echo $f*$g; } Main3 (2,3); Echo"<br/>"; //functions with variable parameters (the number of parameters can be changed) functionMain4 () { for($i= 0;$i<Func_num_args();$i++)    {        $array=Func_get_args();//gets the input parameter, which is an array        Echo $array[$i]." <br/> "; }} Main4 (1,2,6);//the number of parameters can be changed//function parameterized (in other languages called proxies or delegates)functionIndex2 () {Echo"BB"; }@$hanshu=index2;//function Variable parameterEcho $hanshu();//parametric variable function//Direct output    Echo"<br/>"; STR ($hanshu); functionStr$a) {     Echo $a(); }//by method call?>

Notes

Custom functions:
1. Function of the default value:
function Main ($a =5, $b =6)
{
Echo $a * $b;
}

2. Functions of variable parameters:
function Main ()
{
for ($i =0; $i <func_num_args (); $i + +)
{
$array = Func_get_args ();
echo $array [$i]. " <br> ";
}
}
Main (All-in-all)//variable Quantity

3. function parameterization (referred to as proxy or delegate in other languages)
function Index2 ()
{
echo "BB";
}
@ $hanshu = Index2;
$hanshu ();

php--Custom Functions

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.