PHP移動互連網開發筆記(5)——基礎函數庫_PHP教程

來源:互聯網
上載者:User
一、數學函數庫

● floor

舍一取整(向下取整)

float floor (float $value);

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


● ceil

進一取整(向上取整)

float ceil(float $value);

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

● max

取最大值

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

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

● min

取最小值

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

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

● pow

冪運算

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

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

● sqrt

取平方根

float sqrt(float $arg)

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

● rand

產生隨機數

int mt_rand(int $min, int max);

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

● mt_rand

產生一個更好的隨機數

int mt_rand(int $min, int max);

和上面的rand用法及輸出結果類似,這個比rand快4倍。

● round

四捨五入

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

第二個參數可選,規定小數點保留位元

● number_format

通過千位分組格式化數字

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

二、日期時間函數庫

● time

返回當前Unix時間戳記

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

格式化一個本地時間/日期

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

● getdate

取得日期/時間資訊

array getdate([int timestamp]);

MD5雜湊
 

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

strpos

返回一個字元在另一個字元第一次出現的位置

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


http://www.bkjia.com/PHPjc/755796.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/755796.htmlTechArticle一、數學函數庫 ● floor 舍一取整(向下取整) float floor (float $value); ");echo(floor(0.40)." ");echo(floor(5)." ");echo(floor(5.1)." ");echo(floor(-5.1)." ");ec...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.