1 / 29

PHP

PHP. Array. Array. การสร้างอาร์เรย์ผ่านฟังก์ชัน array(); กำหนดโดย Array Identifier $ array_name []. Array();. $Variable = array(value1,value2,value3,……); $nick = array(“ Som ”, “ Bom ”, “Beer”, “Mew”); $animal = array(“Tiger”, “Dog”, “Lion”, “Elephant”);. Array Identifier.

quang
Télécharger la présentation

PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Array

  2. Array • การสร้างอาร์เรย์ผ่านฟังก์ชัน array(); • กำหนดโดย Array Identifier $array_name[]

  3. Array(); • $Variable = array(value1,value2,value3,……); $nick = array(“Som”, “Bom”, “Beer”, “Mew”); $animal = array(“Tiger”, “Dog”, “Lion”, “Elephant”);

  4. Array Identifier $Variable[ ] $animal[] = “Tiger”; $animal[] = “Dog”; $animal[] = “Lion”; $animal[] = “Elephant”; $animal[] = “Horse”; echo $animal[2] ; // Lion

  5. foreach $name = array(“Boy”, “Mint”, “Cat”, “Bom”); foreach($name as $val) { echo $val . “<br>”; } Boy Mint Cat Bom

  6. ฟังก์ชันที่เกี่ยวกับ array • count()นับสมาชิกอาร์เรย์ • array_merge()รวมอาร์เรย์ • array_push()เพิ่มอาร์เรย์ • sort()เรียงข้อมูล

  7. PHP Function

  8. Function • ฟังก์ชันที่มากับ PHP (Built-in Function) • ฟังก์ชันที่ผู้ใช้สร้างขึ้นเอง

  9. ฟังก์ชันที่มีมากับ PHP • ฟังก์ชันที่เกี่ยวกับวันและเวลา • ฟังก์ชันที่เกี่ยวกับการคำนวณทางด้านคณิตศาสตร์ • ฟังก์ชันที่เกี่ยวกับการจัดการกับสตริงหรือข้อความ • ฟังก์ชันที่เกี่ยวกับการติดต่อกับฐานข้อมูลประเภทต่างๆ

  10. ฟังก์ชันที่ผู้ใช้สร้างขึ้นเองฟังก์ชันที่ผู้ใช้สร้างขึ้นเอง function function_name($argument1,$argument2,…) { ……….. } function_nameชื่อฟังก์ชัน $argumentตัวแปรที่ใช้ในการรับ-ส่งค่าระหว่างฟังก์ชัน

  11. การเรียกใช้งานฟังก์ชันการเรียกใช้งานฟังก์ชัน • function_name(); ไม่มีการส่งค่าไปยังฟังก์ชัน • function_name($x,$y); มีการส่งค่าไปยังฟังก์ชัน 2 ค่า

  12. การคืนค่าจากฟังก์ชัน function Multiply_Num($a) { return ($a*5); } $x = Multiply_Num(20); echo $x; //100

  13. การแสดงค่าจากฟังก์ชันการแสดงค่าจากฟังก์ชัน function Multiply_Num($a) { $x = $a*5; echo $x; } Multiply_Num(20); //100

  14. String Function • strlen() จำนวนตัวอักษรของข้อความ • strpos() ค้นหาตำแหน่งของตัวอักษรในข้อความ • substr() ตัดข้อความ • str_replace() ค้นหาและแทนที่ข้อความ • strtolower() ทำข้อความเป็นตัวอักษรเล็ก • strtoupper() ทำข้อความเป็นตัวอักษรใหญ่ • ucfirst() ทำตัวอักษรแรกของข้อความเป็นตัวอักษรใหญ่ • ucwords() ทำตัวอักษรแรกของทุกคำในข้อความเป็นตัวอักษรใหญ่

  15. String Function • ltrim() ตัดค่าว่างทางด้านซ้ายออก • rtrim() / chop() ตัดค่าว่างทางด้านขวาออก • trim() ตัดค่าว่างทั้งด้านซ้ายและขวาออก • chr() แปลงรหัส ASCII เป็นตัวอักษร • ord() แปลงตัวอักษรเป็นรหัส ASCII • strrev() เรียงสลับข้อความจากหลังไปหน้า • explode() แยกข้อความโดยใช้เครื่องหมายแยก (Array)

  16. PHP Time & Date / Form

  17. Date / Time • time(); Time Stamp //1387094451 • getdate(); วันและเวลาปัจจุปัน คืนค่ากลับในรูปแบบ อาร์เรย์ getdate(Key); getdate(second); วินาที getdate(minute); นาที getdate(0); Timestamp

  18. Date/ Time date() • date(format, timestamp) formatรหัสในการจัดรูปแบบวันและเวลา timestampค่าตัวเลขที่ได้จากฟังก์ชัน time() หรือ mktime() ไม่ระบุก็ได้

  19. mktime() ฟังก์ชันในการสร้าง Time Stamp จากวันและเวลาที่ระบุ • mktime(hour,minute,second,month,day,year) hourชั่วโมง minuteนาที second วินาที month เดือน day วันที่ year ปี

  20. Check Date checkdate() หากถูกต้อง จะคืนค่า 1 • checkdate(month, day, year); monthเดือน day วันที่ year ปี ค.ศ.

  21. Form <form></form> nameชื่อฟอร์ม method ประเภทการส่งข้อมูล - get - post actionurlหรือ หน้าที่ต้องการส่งค่าไป <form name=“form1” method=“POST” action=“index2.php”>

  22. <input type=“” name=“” value=“”> • text • password • checkbox • radio • submit • reset • button • hidden • file • image

  23. <select name=“”> <option value=“”>….</option> </select> • <textarea name=“” cols=“” rows=“”>….</textarea>

  24. $_POST[“ชื่อinput”] ค่าตัวแปรในรูปแบบของ POST • $_GET[“ชื่อinput”]ค่าตัวแปรในรูปแบบของ GET • isset()ตรวจสอบว่ามีการประกาศค่าตัวแปรหรือไม่

  25. index.php <form method=“post” action=“index2.php”> <input type=“text” name=“Fname”> <input type=“submit” name=“SM” value=“OK”> </form> ------------------------------------------------------------------------------------------------------ index2.php <? if(isset($_POST[“Fname”])){ echo “My Name is ”.$_POST[“Fname”]; } ?>

  26. index.php <form method=“get” action=“index2.php”> <input type=“text” name=“Fname”> <input type=“submit” name=“SM” value=“OK”> </form> -------------------------------------------------------------------------------- http://localhost/index.php?Fname=ton Index2.php <? if(isset($_GET[“Fname”])){ echo “My Name is ”.$_GET[“Fname”]; } ?> My Name is ton

More Related