PHP function function explained _php tutorial

Source: Internet
Author: User
The real power of PHP is derived from its functions, but some PHP functions are not fully utilized, and not everyone will read the manuals and function references from page-to-page, which will introduce you to these useful functions and functions.

  1, the function of any number of parameters
As you probably already know, PHP allows you to define the functions of optional parameters. But there are also methods that allow any number of function parameters to be fully allowed. The following are examples of optional parameters:

The following is the referenced content:
Functionwith2optionalarguments
Functionfoo ($arg 1= ", $arg 2 =") {
echo "Arg1: $arg 1";
echo "ARG2: $arg 2";
}

Foo (' Hello ', World ');
/*prints:
Arg1:hello
Arg2:world
*/

Foo ();
/*prints:
Arg1:
ARG2:
*/

Now let's look at how to create a function that accepts any number of arguments. This time you need to use the Func_get_args () function:

The following is the referenced content:
Yes,theargumentlistcanbeempty
Functionfoo () {
Returnsanarrayofallpassedarguments
$args =func_get_args ();
foreach ($argsas $k=> $v) {
echo "Arg". ($k 1). ": $v";
}
}

Foo ();
/*printsnothing*/

Foo (' Hello ');
/*prints
Arg1:hello
*/

Foo (' Hello ', ' world ', ' again ');
/*prints
Arg1:hello
Arg2:world
Arg3:again
*/

http://www.bkjia.com/PHPjc/486209.html www.bkjia.com true http://www.bkjia.com/PHPjc/486209.html techarticle the real power of PHP is derived from its functions, but some PHP functions are not fully utilized, and not everyone will read the manual and the function reference from one page to the next, here ...

  • 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.