PHP mobile Internet Development notes (5) basic function libraries

Source: Internet
Author: User
I. mathematical function library ● floor rounding (rounding down) floatfloor (float $ value );? Phpecho (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 one-to-one INTEGER (rounded up) floatceil (f

I. mathematical function library ● floor rounding (rounding down) float floor (float $ value );? Phpecho (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 one-to-one INTEGER (rounded up) float ceil (f

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

  

● Microtime

Returns the current Unix Timestamp and the number of microseconds.

Mixed microtime ([bool get_as_float]);

●Date_default_timezone_set

Set Default Time Zone

Bool date_default_timezone_set (string timezone_identifier );

●Date_default_timezone_get

Get Default Time Zone

String date_default_timezone_get (void );

Iii. Character function library

Strlen

Returns the string length.

Int strlen (string $ str );

Strtolower

String to lowercase

String strtolower (string $ str );

Strtoupper

Convert string to uppercase

String strtoupper (string $ str );

Ucfirst

Uppercase letters

String ucfirst (string $ str );

Ucwords

Converts the first letter of each word to an uppercase letter.

String ucwords (string $ str );

Ltrim

Removes spaces or other characters from the start of a string.

String ltrim (string $ str [, string $ charlist]);

Rtrim

Removes spaces or other characters from the end of a string.

String rtrim (string $ str [, string $ chirlist]);

Trim

Removes spaces or other characters from the start and end of a string.

Str_replace

Character replacement

Mixed str_ireplace (mixed $ search, mixed $ replace, mixed $ subject, [int $ count]);

Str_ireplace

Character replacement

Mixed str_ireplace (mixed $ search, mixed $ replace, mixed $ subject, [int $ count]);

Md5

Calculate the MD5 hash of a string

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.