Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP
PHP
  1. ฟังก์ชัน imagecolorresolvealpha() ใน PHP

    ฟังก์ชัน imagecolorresolvealpha() หา index ของสีที่ระบุพร้อมค่า alpha (ความโปร่งใส) ไวยากรณ์ imagecolorresolvealpha (img, red, green, blue, alpha) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() red: สีแดง green: สีเขียว blue: สีน้ำเงิน alpha: 0-127 (0 = โปร่งใสเต็มที่, 127 = ทึบเต็มที่) คืนค่า Co

  2. ฟังก์ชัน imagecolorsforindex() ใน PHP

    ฟังก์ชัน imagecolorsforindex() ดึงค่าสี (RGBA) ของ palette index ที่ระบุ ไวยากรณ์ imagecolorsforindex (img, index) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() Index: palette index คืนค่า Associative array มี keys: red, green, blue, alpha ตัวอย่าง <?php $img = imagecreatefrompng(https://www

  3. ฟังก์ชัน imagecolorset() ใน PHP

    ฟังก์ชัน imagecolorset() ตั้งค่าสีสำหรับ palette index ที่ระบุ ใช้สร้างเอฟเฟกต์ flood-fill ใน palette images ไวยากรณ์ imagecolorset (img, index, red, green, blue, alpha) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() index: Index ใน palette red: ค่าสีแดง green: ค่าสีเขียว blue: ค่าสีน้ำเงิน alpha:

  4. ฟังก์ชัน imagecolorstotal() ใน PHP

    ฟังก์ชัน imagecolorstotal() นับจำนวนสีใน palette ของภาพ ไวยากรณ์ imagecolorstotal (img) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() คืนค่า จำนวนสีใน palette ตัวอย่าง <?php $img = imagecreatefromgif(https://www.tutorialspoint.com/images/html.gif); echo Number of Colors = . imagecolorstota

  5. ฟังก์ชัน imagecolorresolve() ใน PHP

    ฟังก์ชัน imagecolorresolve() หา index ของสีที่ระบุ หรือสีที่ใกล้เคียงที่สุดใน palette ไวยากรณ์ imagecolorresolve (img, red, green, blue) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() red: ค่าสีแดง (0-255) green: ค่าสีเขียว (0-255) blue: ค่าสีน้ำเงิน (0-255) คืนค่า คืน color index ตัวอย่าง <?p

  6. ฟังก์ชัน imagecolortransparent() ใน PHP

    ฟังก์ชัน imagecolortransparent() ตั้งค่าสีโปร่งใส (Transparent) ของภาพ ไวยากรณ์ imagecolortransparent (img, color) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() color: Color identifier จาก imagecolorallocate() คืนค่า คืน identifier ของสีโปร่งใสใหม่ -1 ถ้าไม่ระบุสีและภาพไม่มีสีโปร่งใส ตัวอย่าง &l

  7. ฟังก์ชัน imagecolormatch() ใน PHP

    ฟังก์ชัน imagecolormatch() ปรับสีของ palette image ให้ใกล้เคียง true color image มากขึ้น ไวยากรณ์ bool imagecolormatch (img1, img2) พารามิเตอร์ img1: True color image จาก imagecreatetruecolor() img2: Palette image resource ขนาดเท่ากับ img1 คืนค่า TRUE ถ้าสำเร็จ FALSE ถ้าล้มเหลว ตัวอย่าง <?php

  8. ฟังก์ชัน imageconvolution() ใน PHP

    ฟังก์ชัน imageconvolution() ใช้การคอนฟลูชัน (Convolution) กับภาพ โดยใช้ matrix 3x3 ไวยากรณ์ bool imageconvolution (img, matrix, div, offset) พารามิเตอร์ img: ภาพจาก imagecreatetruecolor() matrix: Matrix 3x3 เป็น array ของ 3 arrays ที่มี 3 floats div: ตัวหารสำหรับ normalization offset: ค่า offset ข

  9. ฟังก์ชัน imagecreatetruecolor() ใน PHP

    ฟังก์ชัน imagecreatetruecolor() สร้างภาพ true color ใหม่ ไวยากรณ์ imagecreatetruecolor (width, height) พารามิเตอร์ width: ความกว้างของภาพ height: ความสูงของภาพ คืนค่า คืน resource identifier ของภาพ หากสำเร็จ FALSE หากล้มเหลว ตัวอย่าง <?php $img = imagecreatetruecolor(600, 500); echo imagesy(

  10. การเปรียบเทียบวันที่ (Date Comparison) ใน PHP

    เปรียบเทียบวันที่ใน PHP ง่ายถ้ารูปแบบเดียวกัน แต่ล้มเหลวถ้ารูปแบบต่างกัน มีหลายวิธี: กรณีที่ 1: รูปแบบเดียวกัน ใช้ comparison operator ตรงๆ $date2) echo $date1 is latest than $date2; else echo $date1 is older than $date2; ?> ผลลัพธ์ 2019-03-26 is latest than 2018-11-24 กรณีที่ 2: รูปแบบต่างกั

  11. การต่อสตริง (Concatenation) ใน PHP

    PHP มี String Operators 2 ตัว: Concatenation Operator (.): รวมสตริง 2 ตัว กลายเป็นสตริงใหม่ Concatenating Assignment Operator (.=): ต่อสตริงขวาเข้ากับสตริงซ้าย ตัวอย่าง Concatenation (.) <?php $a = Good; $b = Morning; $c = $a.$b; echo $c ; ?> ผลลัพธ์ Goodmorning ตัวอย่าง Concatenating

  12. เปรียบเทียบ && และ AND Operator ใน PHP

    PHP มี logical operators && และ AND ทั้งคู่คืนค่า true/false (Boolean operators) แตกต่างกันที่ precedence (ลำดับความสำคัญ) AND Operator คืน true ก็ต่อเมื่อทั้งสองเงื่อนไขเป็น true ตัวอย่าง <?php $val1 = 20; $val2 = 50; if ($val1 == 20 and $val2 == 50) echo True; else echo False; ?> ผลลัพธ์

  13. การเปรียบเทียบค่า Floating Point ใน PHP

    ใน PHP การเทียบค่า floating point ด้วย == มักให้ผลผิด เพราะการเก็บค่าภายใน (internal representation) ไม่แม่นยำ ต้องใช้วิธีอื่น ตัวอย่างปัญหา <?php $a = 0.14; $b = 1 - 0.86; // 0.14 if($a == $b) echo a and b are same; else echo a and b are not same; ?> ผลลัพธ์ a and b are not same. วิธีแก

  14. Static Method และ Instance Method ใน PHP

    ใน PHP Instance methods เป็นแนวทางหลัก แต่ Static methods ก็มีจุดประสงค์เฉพาะ Instance method ผูกกับ object ของคลาส Static method ผูกกับคลาสโดยตรง Static Method ใช้เมื่อข้อมูลคงที่สำหรับทุก object ของคลาส เรียกใช้โดยไม่ต้องสร้าง object ตัวอย่าง <?php class Car{ static function getColor(){

  15. แปลง Object เป็น Array ใน PHP

    ใน PHP ต้องการแปลง Object เป็น Associative Array บ่อยครั้ง มี 2 วิธีหลัก: วิธีที่ 1: json_decode + json_encode json_encode() แปลง object เป็น JSON string json_decode() แปลง JSON string เป็น array (พารามิเตอร์ true) ตัวอย่าง lastname = $lastname; } } $myObj = new student(Alex, Stokes); echo

  16. Final Class และ Final Method ใน PHP

    คีย์เวิร์ด final ใน PHP 5 ใช้กับ OOP ป้องกันการ override method หรือการ extend class ตัวอย่าง: Final Method calculate(10,10); ?> ผลลัพธ์ PHP Fatal error: Cannot override final method BaseClass::calculate() คำอธิบาย calculate() ใน BaseClass เป็น final ChildClass ไม่สามารถ override ได้ ตัวอย่าง:

  17. Abstract Class ใน PHP

    PHP 5 มี OOP model Abstract Class เป็นคลาสที่ประกาศด้วยคีย์เวิร์ด abstract มี abstract methods อย่างน้อย 1 เมธอด Abstract method มีแค่ชื่อและ arguments ไม่มี body ไม่สามารถสร้าง object จาก abstract class ได้ ต้อง extend เป็น child class implement body ของ abstract methods แล้วค่อยสร้าง object จาก c

  18. Encapsulation ใน PHP

    OOP ใน PHP 5 ช่วยสร้างแอปพลิเคชัน Encapsulation คือการห่อหุ้มข้อมูลและเมธอดเป็นหน่วยเดียว (Class) เป็นกลไกป้องกัน data members และ methods ในคลาส ใน PHP encapsulation ทำให้โค้ดปลอดภัยและแข็งแกร่ง ซ่อนการ implement จริงจากผู้ใช้ ไม่อนุญาตให้เข้าถึง/แก้ไข data members โดยตรง ต้องผ่านเมธอดที่กำหนด ตัว

  19. ความแตกต่างระหว่าง Abstraction และ Encapsulation ใน PHP

    PHP 5 เพิ่ม OOP model เข้ามา ความแตกต่างระหว่าง Abstraction และ Encapsulation: Encapsulation (การห่อหุ้ม) รวม data members (variables) และ implementation details เป็นหน่วยเดียวคือ Class เป็นกลไกป้องกัน data members ไม่ให้เข้าถึงโดยตรงจากภายนอก Data members เข้าถึงได้เฉพาะผ่าน methods ของคลาสเดียวก

  20. ความแตกต่างระหว่าง include(), require(), include_once(), require_once() ใน PHP

    ฟังก์ชันทั้ง 4 ใช้ include ไฟล์ใน PHP แต่ต่างกันในรายละเอียด: include() include ไฟล์ หาไม่เจอ แสดง Warning แต่ไม่หยุด script require() include ไฟล์ หาไม่เจอ แสดง Fatal Error และหยุด script include_once() include ไฟล์แค่ครั้งเดียว ถ้า include แล้วจะไม่ include ซ้ำ หาไม่เจอ Warning ไม่หยุด script req

Total 1286 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:32/65  20-คอมพิวเตอร์/Page Goto:1 26 27 28 29 30 31 32 33 34 35 36 37 38