Statement
Branch statements
If statement
If
If.........else
If.......else If.....else
Nesting of If
Switch statement
Looping statements
For loop
Function
4 Elements of a function:: return type, function name, parameter, function body
1 // how functions are defined 2 function Show () 3 {4 Echo "Hello"; 5 }6// call mode 7 Show ();
1 // function with Parameters 2 function Show ($a,$b)3{4 echo$a+ $b; 5 }6 Show (3,4)
1 // functions with default values 2 function Show ($a=5,$b=5)3{4 echo$a+ $b ; 5 }6 Show ();
1 //functions with variable parameters2 functionShow ()3 {4 $attr=Func_get_args();//get parameters for a function5 $sum=0;6 for($i= 0;$i<Count($attr);$i++)//Func_num_args () Gets the number of arguments7 {8 $sum=$sum+$attr[$i];9 }Ten Echo $sum;
1 //Have return worthy function 2 function Show () 3 {4 return "AAAA"; 5 }6echo Show ();
1 //Common Functions2 Echo Rand();//random number generation function3 Echo Time();//take the current date time4 Echo Date("Y-m-d h:i:s", Time());//Format Date Time5 Echo Strtotime("2015-05-06");//Convert DateTime format to timestamp
1 //String Handling Functions2 $a= "Hello";3 Echo strlen($a);//returns the length of the string * * * *4 Echo strcmp("Hello", "AA");//compares two strings for equality returns 0, not equal returns 15 Echo strcasecmp("Hello", "Hello");//compares two strings for equality, case insensitive6 Strtolower("HELLO");//Convert a string to lowercase * * * *7 Strtoupper("Hello");//Convert to uppercase8 $str= "Hello|world|join|on";9 Var_dump(Explode("|",$str));//splits the string, returning the array. ****
Ten $attr=Array("AAA", "BBB", "CCC"); One implode("|",$attr);//stitching an array into a string * * *
A Echo Substr_replace($str, "AAA", 0,5);//Replace string (a location) * * * * - Echo Str_replace("L", "a",$str);//Find Replacement * * * * - Echo substr($str, 0,5);//Intercepting Strings * * * *
Some small knowledge points
Both single and double quotation marks can define a string
1. You can use the escape character in double quotation marks, which cannot be used in single quotation marks.
2. Double quotation mark inside can parse variable, single quotation mark not
1 // Defining a String (block) 2 $str =<<<str //str cannot have anything before 3 <div style= "background:red; color: White width:100px;height:30px ">hello</div>4 <div style=" background:red; Color:white; width:100px;height:30px ">world</div>5 STR; // you can't have anything before str. 6 Echo $str;
PHP Basic Statement