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