PHP functions and passing parameters

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags basic calling customize echo function functions php php tutorial

This tutorial is about calling functions and function definition syntax, and talking about variables in functions and passing numeric methods to functions.

The basis of a function

The PHP tutorial provides a number of functions and allows the user to customize the function,

PHP function Definition Instance

<?php
function Mycount ($inValue 1, $inValue 2)
{
$AddValue = $inValue 1+ $inValue 2;
return $AddValue; Return calculation results
}
$Count = Mycount (59,100);
Echo $Count; Output 159
The?> function can be used anywhere but defined.

Second, the function passes the parameter

PHP function parameters in the definition of the definition, the function can have any number of parameters, the most common method of transmission, is delivered by value. or by reference and default parameter values are relatively few.

Instance

<?php
function MyColor ($inColor = "Blue")
{
Return "My favorite color: $inColor. N";
}
Echo MyColor ();
echo MyColor ("pink");
?> generally passed values are not changed by internal changes in functions. Unless it's a global variable or reference. php Function Reference Instance

<?php
Function Str_unite (& $string)
{
$string. = ' also like blue. '
}
$str = ' Like Red, '
Str_unite ($STR);
Echo $str; Output: ' Like red, also like blue. '
?>

Global variables

<?php
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>

Related Article

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.