PHP Basic Syntax-functions

Source: Internet
Author: User

Function four elements: 1. Return type 2. function name 3. Parameter 4. function body Functions PHP () {echo ' Hello ';} PHP ();//function with parameters Show ($a, $b) {echo $a + $b;} Show (3,4);//function with default value show ($a =5, $b =5) {echo $a + $b;} Show ()///variable function functions Show () {$attr =func_get_args ();//Get the parameters of the function $sum=0;for ($i =0; $i <count ($attr); $i + +)//func_ Num_args () Gets the number of arguments with count (); {$sum + = $attr [i];} echo $sum;} Functions with return value function show () {return ' AAAA ';} Echo Show (); Show ()///function common//generate random number of functions echo rand (1,10); echo time ();//Go to current datetime date_default_timezone_set (' PRC '); echo Date ("Y-m-d h:i:s:ms", Time ());//Format datetime $ A = Strtotime ("2016-5-6");//convert datetime format to timestamp echo date ("y-m-d");//String handler function $a= " Hello|world|on|join "; Echo strlen ($a); Returns the length of the string √echo strcmp ("Hello", "hello");//Determines whether two strings are equal, equals returns 0, not equal returns 1 (case-sensitive) echo strcasecmp ("Hello", "hello");// Determines whether two strings are equal, returns equal to 0, does not return 1 (case insensitive) echo strtolower ("Hello"),//converts the string to lowercase √echo strtoupper ("Hello"), or converts the string to uppercase √var_ Dump (Explode ("|", $a));//split string, return array √ $str =array ("AAA", "BBB", "CCC"), Echo implode ("|", $STR);//concatenation of arrays into strings √echo substr_ Replace ($a, "AAA", 0,5);//Replace String onePosition √echo str_replace ("L", "a", $a);//Find replacement √echo substr ($a, 0,5);//intercept string Yes 

  

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