Home  >  Article  >  Backend Development  >  PHP Mobile Internet Development Notes (5) - Basic Function Library_PHP Tutorial

PHP Mobile Internet Development Notes (5) - Basic Function Library_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:32:15913browse

1. Math 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=',');

2. Date and time function library

● 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());
?>
PHP Mobile Internet Development Notes (5) - Basic Function Library_PHP TutorialMD5 ha Hope

string 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]);


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755796.htmlTechArticle1. Mathematics function library ● floor rounding (rounding down) float floor (float $value) ; ");echo(floor(0.40)." ");echo(floor(5)." ");echo(floor(5.1)." ");echo(floor(-5.1)." ");ec ...
Statement:
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