3.1 php basic functions(math, date, string)
Mathematical function: max mixed max(number $arg1,number $arg2,...) Find the maximum value in a set of data Mixed refers to mixed type (undefined type)
min mixed min(number $arg1,number $arg2,...) Find the minimum value in a set of data
ceil float ceil(float $value) Round up
floor float floor(float $value) Round down
round float round(float $value) Rounding
rand int rand([int $min], int $max) generates a random integer [] indicating that the parameters are optional.
mt_rand int mt_rand([int $min], int $max) generates better random numbers and improves efficiency.
Date function: time int time(void) returns the current timestamp. The artificially specified number of seconds from 1970.01.01 00:00:00 to the present.
date string date(date format [timestamp]) Format a local time/date
Format: Year Y
m month
d day
H time
i points
s seconds
strtotime int strtotime(string $time [,int $now] ) Parses the date and time description of any English text into a timestamp.
date_default_timezone_set (time zone) Set the time zone. Time zone of the People's Republic of China: "Asia/Shanghai". // For temporary settings, you need to change the configuration file php.ini for permanent settings: date.timezone=PRC
String function: strlen int strlen(string $string) Get the length of the string
strtolower string strtolower(string $string) string lowercase
strtoupper string strtoupper(string $string) string in all uppercase
ucfirst string ucfirst(string $string) Capitalize the first letter in the string
ucwords string ucwords(string $string) The first letter of each word is capitalized
strrev .
trim string trim(string $string) removes the spaces at the beginning and end of the stringstr_replace mixed str_replace(mixed $search,mixed $replace, mixed $subject [, int &$count]) Replacement
strpos int strpos(string $haystack, mixed $neddle[, int $offset=0]) Find the position where the character first appears
substr string substr(string $string, int $start[, int $length]) intercepts the string
md5 string mds(string $str) String encryption
unset void unset(mixed $var [,mixed $var [,$...]]); Release variables
3.2 Loops in process control
for
for(loop condition){Loop body!
}
while
Starting conditions;while(termination condition){
loop body;
Step size; //Note: If you don’t write the step size, you will fall into an infinite loop
}
do...while
Starting conditions;do{
Loop body;
step size;
}while(termination condition);
Note: No matter whether the termination condition is true or not, it will be executed once.
break continue Change loop status
break terminates the loop
continue ends this loop loop body continues the next loop