Statement:
One: Branch statements
1.if (condition 1) {Satisfies condition 1 execution}
2.if (condition 1) {satisfies condition 1 execution}else{does not meet condition 1 execution}
3.if (condition 1) {satisfies condition 1 executes}else if (condition 2) {satisfies condition 2 execution}else{does not satisfy condition 1 and condition 2 executes}
Nesting of 4.if
5.switch....case
$a = 2;
Switch ($a)
{
Case 1:
echo "111111";
Break
Case 2:
echo "222222";
Break
Case 3:
echo "333333";
Break
Case 4:
echo "4444444";
Break
Case 5:
echo "555555";
Break
}
Two: Circular statements
1.for Cycle
for ($i =0; $i <10; $i + +)
{
echo "This is the first". $i. " Sub-cycle <br> ";
}
2.while Cycle
$i = 0;
while ($i <20)
{
echo "This is a while loop out of code <br>";
$i + +;
}
Function:
1. Four elements: function name parameter function body return type
How to define in C # or Java:
public void Main (int a, int b)
{
function body;
}
How PHP is defined:
function Main ()
{
echo "Hello";
}
Common functions:
1. Random number generation: rand (); can have two parameters, two integers, limit the range of random numbers
2. Date-time function:
Time (); Takes the current datetime, is a UNIX timestamp
Date (), requires a parameter (formatted string), can be taken out of the current datetime and formatted display
Date (), two parameters, formatted to display data of any datetime type
3. Modify the default time zone:
Found in PHP config file php.ini date.timezone = europe/paris change Europe/paris to Etc/gmt-8
Custom functions:
1. Function of the default value:
function Main ($a =5, $b =6)
{
Echo $a * $b;
}
2. Functions of variable parameters:
function Main ()
{
for ($i =0; $i <func_num_args (); $i + +)
{
$array = Func_get_args ();
echo $array [$i]. " <br> ";
}
}
3. function parameterization (referred to as proxy or delegate in other languages)
function Index2 ()
{
echo "BB";
}
@ $hanshu = Index2;
$hanshu ();
String processing:
strlen ("AAA"); Take the length of the string * * *
strcmp ("AAA", "AAA"); compare two strings, same words output 0, different output-1
STRCASECMP ("AAA", "AAA"); compare two strings, case insensitive
Strtolower ("abcdefgh"); turn lowercase
Strtoupper (); turn caps
$array = Explode ("|", $s); splits the string, returns an array of strings * * *
$s = implode ($array); converting an array to a string
$s = substr_replace ($s, "China"); Replace string with position
$s = Str_replace ("L", "dog", $s); replacement string, equivalent to a lookup substitution in Notepad
$s = substr ($s, 4,10), intercept string, intercept based on the end position of the start position * * *
PHP statement function string processing