Php Tutorial 2 (function implementation)

Source: Internet
Author: User
Tags php tutorial

The source code is implemented by functions, including counting, string connection, and function return results.

Function

<? Php Tutorial
Function mycount ($ invalue1, $ invalue2)
{
$ Addvalue = $ invalue1 + $ invalue2;
Return $ addvalue; // return the calculation result
}
$ Count = mycount (59,100 );
Echo $ count; // output 159
?>

Function call

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

Function return value

<? Php
Function mycolor ($ incolor = "blue ")
{
Return "my favorite colors: $ incolor. n ";
}
Echo mycolor ();
Echo mycolor ("pink ");
?>


Global variables

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

Simple digital computing

<? Php
Function square ($ num)
{
Return $ num * $ num;
}
Echo square (4); // output '16 '.
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.