PHP mobile internet development notes (5)-basic function libraries

Source: Internet
Author: User
Tags md5 hash
I. mathematical function library ● floor provides an integer (rounded down) floatfloor (float $ value); ● ceil performs an integer (rounded up) floatceil (float $ value ); ● max takes the maximum value of mixedmax (mixed $ value, mixed $ value,); ●

I. mathematical functions Library

● Floor

Rounding (rounding down)

Float floor (float $ value );

  ");echo(floor(0.40)."
");echo(floor(5)."
");echo(floor(5.1)."
");echo(floor(-5.1)."
");echo(floor(-5.9)."
")?>


● Ceil

One integer (rounded up)

Float ceil (float $ value );

  ");echo(ceil(0.40)."
");echo(ceil(5)."
");echo(ceil(5.1)."
");echo(ceil(-5.1)."
");echo(ceil(-5.9)."
")?>

● Max

Maximum value

Mixed max (mixed $ value, mixed $ value ,......);

  ");echo(max(-3,5)."
");echo(max(-3,-5)."
");echo(max(7.25,7.30)."
");?>

● Min

Minimum value

Mixed min (mixed $ value, mixed $ value ,......);

  ");echo(min(-3,5)."
");echo(min(-3,-5)."
");echo(min(7.25,7.30)."
");?>

● Pow

Power operation

Number pow (number $ base, number $ expr );

  ";echo pow(6,2)."
";echo pow(-6,2)."
";echo pow(-6,-2)."
";echo pow(-6,5.5)."
";?>

● Sqrt

Take the square root

Float sqrt (float $ arg)

  ";echo(sqrt(1))."
";echo(sqrt(9))."
";echo(sqrt(0.64))."
";echo(sqrt(-9))."
";?>

● Rand

Generate random number

Int mt_rand (int $ min, int max );

  ";echo rand(10,100)."
";?>

● Mt_rand

Generate a better random number

Int mt_rand (int $ min, int max );

Similar to the preceding rand usage and output results, this is four times faster than rand.

● Round

Rounding

Float round (float $ val [, int $ precision = 0])

Optional; number of decimal places

Number_format

Format a number using a thousand-bit grouping

Float number_format (float $ number, int $ decimals = 0, string $ dec_point = ", ', string $ thousands_sep = ',');

II. date and time function library

● Time

Returns the current Unix timestamp.

Int time (void );

  ";$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secsecho 'Now:       '. date('Y-m-d') ."
";echo 'Next Week: '. date('Y-m-d', $nextWeek) ."
";?>

● Date

Format a local time/date

String date (string format [, int timestamp]);

● Getdate

Get date/time information

Array getdate ([int timestamp]);

  
MD5 hash

String md5 (string $ str [, bool $ raw_output = false]);

Strpos

Returns the position where one character appears for the first time.

Int strpos (string haystack, mixed needle [, int offset]);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.