Home > php教程 > php手册 > body text

PHP Notes 3.0 basic functions and loops in process control

WBOY
Release: 2016-11-16 10:24:06
Original
1645 people have browsed it

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 string

str_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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template