Home >Backend Development >PHP Tutorial >PHP Mobile Internet Development Notes (5) - Basic Function Library_PHP Tutorial
1. Math function library
2. Date and time function library● floor
Round to the nearest whole number (Round down)
float floor (float $value);
<?php echo(floor(0.60)."<br>"); echo(floor(0.40)."<br>"); echo(floor(5)."<br>"); echo(floor(5.1)."<br>"); echo(floor(-5.1)."<br>"); echo(floor(-5.9)."<br>") ?>
● ceil
Round up (round up)
float ceil(float $value);
<?php echo(ceil(0.60)."<br>"); echo(ceil(0.40)."<br>"); echo(ceil(5)."<br>"); echo(ceil(5.1)."<br>"); echo(ceil(-5.1)."<br>"); echo(ceil(-5.9)."<br>") ?>
● max
Take the maximum value
mixed max(mixed $value, mixed $value, ...);
<?php echo(max(5,7)."<br>"); echo(max(-3,5)."<br>"); echo(max(-3,-5)."<br>"); echo(max(7.25,7.30)."<br>"); ?>
● min
Take the minimum value
mixed min(mixed $value, mixed $value, ...);
<?php echo(min(5,7)."<br>"); echo(min(-3,5)."<br>"); echo(min(-3,-5)."<br>"); echo(min(7.25,7.30)."<br>"); ?>
● pow
Power operation
number pow(number $base, number $expr);
<?php echo pow(4,2)."<br>"; echo pow(6,2)."<br>"; echo pow(-6,2)."<br>"; echo pow(-6,-2)."<br>"; echo pow(-6,5.5)."<br>"; ?>
● sqrt
Take the square root
float sqrt(float $arg)
<?php echo(sqrt(0))."<br>"; echo(sqrt(1))."<br>"; echo(sqrt(9))."<br>"; echo(sqrt(0.64))."<br>"; echo(sqrt(-9))."<br>"; ?>
● rand
Generate random numbers
int mt_rand(int $min, int max);
<?php echo rand()."<br>"; echo rand(10,100)."<br>"; ?>
● mt_rand
Produces a better random number
int mt_rand(int $min, int max);
Similar to the rand usage and output results above, this is 4 times faster than rand.
● round
Round
float round(float $val [, int $precision =0])
The second parameter is optional, specifying the number of decimal places to retain
● number_format
Format number by thousands grouping
float number_format(float $number, int $decimals=0, string $dec_point=",', string $thousands_sep=',');
● time
Returns the current Unix timestamp
int time(void);
<?php echo time()."<br>"; $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."<br>"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."<br>"; ?>
● date
Format a local time/date
string date(string format[, int timestamp]);
● getdate
Get date /Time information
array getdate([int timestamp]);
<?php print_r(getdate()); ?>MD5 ha Hopestring md5(string $str[, bool $raw_output=false]);
strpos
Returns the position of the first occurrence of one character in another character
int strpos(string haystack, mixed needle[, int offset]);