Php functions and passing parameters _ PHP Tutorial

Source: Internet
Author: User
Php functions and passing parameters. This tutorial introduces the function call and function definition syntax, and describes the variables in the function and the numerical method for passing values to the function. This tutorial will introduce the call and determination of functions. This tutorial will introduce the call and definition syntax of functions, as well as the variables in functions and the method for passing numeric values to functions.

This tutorial introduces the function call and function definition syntax, and describes the variables in the function and the numerical method for passing values to the function.

I. Basics of functions

The php Tutorial provides a large number of functions and allows you to customize the functions,

Php function definition instance

Function myCount ($ inValue1, $ inValue2)
{
$ AddValue = $ inValue1 + $ inValue2;
Return $ AddValue; // return the calculation result
}
$ Count = myCount (59,100 );
Echo $ Count; // output 159
?>

Functions can be used anywhere once defined.

II. function parameters

Php functionsWhen defining a function, a parameter is defined. a function can have any number of parameters. The most common transfer method is passed by value. Or the application by reference and default parameter values is relatively small.

Instance

Function myColor ($ inColor = "blue ")
{
Return "my favorite colors: $ inColor. n ";
}
Echo myColor ();
Echo myColor ("pink ");
?>

Generally, the passed value is not changed because of internal changes in the function. Unless it is a global variable or reference.Php functionsReference instance

Function str_unite (& $ string)
{
$ String. = 'also like blue .';
}
$ Str = 'like red ,';
Str_unite ($ str );
Echo $ str; // output result: 'Like red or blue .'
?>

Global variables

$ A = 1;
$ B = 2;
Function Sum ()
{
Global $ a, $ B;
$ B = $ a + $ B;
}
Sum ();
Echo $ B;
?>

Bytes. This tutorial introduces how to call and define 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.