หน้าเว็บ

วันอาทิตย์ที่ 7 ธันวาคม พ.ศ. 2557

PHP Math Functions (ฟังก์ชั่นด้าน คณิตศาสตร์)



PHP bindec() แปลงเลขฐานสองเป็นฐานสิบ
Syntax
1.<?php
2.bindec($value)
3.?>

Sample1.<?php
2.echo bindec('110011')."<br>";
3.echo bindec('000110011')."<br>";
4.echo bindec('111')."<br>";
5.?>

PHP round() ฟังก์ชั่นใช้สำหรับปัดเศษทศนิยม
Syntax
1.<?php
2.round(ข้อมูลตัวเลข, จำนวนหน่วยทศนิยม)
3.?>

Sample

view source
print?
01.<?php
02.echo round(3.4)."<br>"; // 3
03.echo round(3.5)."<br>"; // 4
04.echo round(3.6)."<br>"; // 4
05.echo round(3.6, 0)."<br>"; // 4
06.echo round(1.95583, 2)."<br>"; // 1.96
07.echo round(1241757, -3)."<br>"; // 1242000
08.echo round(5.045, 2)."<br>"; // 5.05
09.echo round(5.055, 2)."<br>"; // 5.06
10.?>

PHP max() ฟังก์ชั่นใช้สำหรับหาค่าสูงสุดใน Array
Syntax1.<?php
2.max($array)
3.?>

Sample
01.<?php
02.echo max(1, 3, 5, 6, 7)."<br>"; // 7
03.echo max(array(2, 4, 5))."<br>"; // 5
04.echo max(0, 'hello')."<br>"; // 0
05.echo max('hello', 0)."<br>"; // hello
06.echo max(-1, 'hello')."<br>"; // hello
07.$val = max(array(2, 4, 8), array(2, 5, 7))."<br>"; // array(2, 5, 7)
08.$val = max('string', array(2, 5, 7), 42)."<br>"; // array(2, 5, 7)
09.?>

PHP min() ฟังก์ชั่นใช้สำหรับหาค่าต่ำสุดใน Array
Syntax
1.<?php
2.min($array)
3.?>

Sample
01.<?php
02.echo min(2, 3, 1, 6, 7)."<br>"; // 1
03.echo min(array(2, 4, 5))."<br>"; // 2
04.echo min(0, 'hello')."<br>"; // 0
05.echo min('hello', 0)."<br>"; // hello
06.echo min('hello', -1)."<br>"; // -1
07.$val = min(array(2, 4, 8), array(2, 5, 1))."<br>"; // array(2, 4, 8)
08.$val = min('string', array(2, 5, 7), 42)."<br>"; // string
09.?>



ที่มา: http://www.sunzan-design.com/2013/03/php-function-defined.html


ไม่มีความคิดเห็น:

แสดงความคิดเห็น