PHP---functions

Source: Internet
Author: User

I. Four elements of a function definition

return type, function name, argument list, function body

1. The simplest way to define
/*function Show ()
{
echo "Hello";
}
Show (); */
2. function definition with parameters
/*function Show ($a)
{
echo $a;
}
Show ("BBBBB"); */
3. function definitions with default values
/*function Show ($a = "C")
{
echo $a;
}
Show (); */
4. There is a return worth function definition
/*function Show ($a, $b)
{
return $a + $b;
}
Echo Show (5,8);
*/
5. Function definitions for variable parameters
/*function Show ()
{
$a = Func_get_args (); Gets the parameters passed in by the user, returns the array
$b = Func_num_args (); Get the number of arguments passed in
$c = 0; Define a variable, store and
for ($i =0; $i < $b; $i + +)
{
$sum = $sum + $a [$i];
}
return $c;
}
Echo Show (1,2,3,4,5,6,7,8,9);
*/

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