Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP
PHP
  1. การสร้าง Instance ของ Child Class ใน Abstract Static Method PHP

    สำหรับสิ่งนี้ ให้ใช้ $anyObjectName = new static() พร้อมกับ selfตัวอย่างโค้ด PHP มีดังนี้customFunction(); } public static function getFullName(){ return static::$fullName; } } class Child extends Base { protected static $fullName = John Doe; protected function c

  2. PHP ลบอักขระ (') ใน string array และแสดงผลในสตริงเดียว

    สมมติ string array ของเราคือ - $full_name= [John Doe,David Miller,Adam Smith]; เราต้องการเอาต์พุตในสตริงเดียว - John Doe, David Miller, Adam Smith สำหรับนี้ ใช้ json_decode() ตัวอย่าง โค้ด PHP ดังนี้ <!DOCTYPE html> <html> <body> <?php $full_name= [John Doe,David Miller,Adam Sm

  3. PHP นับค่าจากอาร์เรย์และแสดงค่าแค่ครั้งเดียวใน foreach loop

    สมมติอาร์เรย์ PHP ของเราคือ $listOfNames = array(John,David,Mike,David,Mike,David); เราต้องการเอาต์พุตแสดงจำนวนค่าในอาร์เรย์ข้างต้นแบบนี้ - 2 ) เพื่อรับจำนวน ใช้ฟังก์ชันในตัว array_count_values() ตัวอย่าง โค้ด PHP ดังนี้ <!DOCTYPE html> <html> <body> <?php $listOfNames = arra

  4. PHP เพิ่มเวลาในหน่วยนาทีใน datetime string

    สำหรับเรื่องนี้ คุณสามารถใช้เมธอด strtotime() Syntax ดังนี้ - $anyVariableName= strtotime(anyDateValue + X minute); คุณสามารถใส่ค่าจำนวนเต็มแทน X ได้ ตัวอย่าง โค้ด PHP ดังนี้ <!DOCTYPE html> <html> <body> <?php $addingFiveMinutes= strtotime(2020-10-30 10:10:20 + 5 minute); ech

  5. PHP ตรวจสอบว่าสตริงไม่มี whitespace

    เพื่อตรวจสอบว่าสตริงไม่มี whitespace ใช้ preg_match() ใน PHP Syntax ดังนี้ preg_match(/\s/,$yourVariableName); ตัวอย่าง โค้ด PHP ดังนี้ <!DOCTYPE html> <html> <body> <?php $name=John Smith; if ( preg_match(/\s/,$name) ){ echo The name (,$name,) has the space; } else {

  6. วิธีที่ง่ายที่สุดในการรวมอาร์เรย์สองตัวใน PHP

    ใช้ array_merge() เพื่อรวมอาร์เรย์สองตัวใน PHP สมมติอาร์เรย์ของเราคือ - $nameArray1 = array(John,David); $nameArray2 = array(Mike,Sam); ตอนนี้ ตั้งค่าอาร์เรย์ทั้งสองข้างต้นใน array_merge() เพื่อรวมพวกเขา Syntax คือดังนี้ - array_merge($yourFirstArrayName, $yourSecondArrayName); ตัวอย่าง โค้ด PHP ดัง

  7. CURL Context Options ใน PHP

    บทนำ CURL context options พร้อมใช้งานเมื่อ CURL extension ถูก compile ด้วยตัวเลือก configure --with-curlwrappers ด้านล่างคือรายการ CURL wrapper context options Method Description method HTTP method ที่ remote server รองรับ ค่าเริ่มต้นคือ GET header Header เพิ่มเติมที่จะส่งระหว่าง request

  8. PHP ทำไม && ไม่ trigger เป็น false

    เพราะถ้าใช้ && ทั้งสองเงื่อนไขต้องเป็น true หากเงื่อนไขใดเป็น false เงื่อนไขรวมจะประเมินเป็น false โค้ด PHP ดังนี้ - ตัวอย่าง <!DOCTYPE html> <html> <body> <?php $firstCondition= John; $secondCondition = David; if ($firstCondition == John && $secondCondition == Da

  9. ฟังก์ชัน strlen() ใน PHP ให้ความยาวผิดของตัวอักษร Unicode?

    เพื่อรับความยาวที่ถูกต้อง ให้ใช้ mb_strlen() สำหรับตัวอักษร Unicode โค้ด PHP ดังนี้ - ตัวอย่าง <?php $unicodeValues = JohnSmȉth; echo The string length with mb_strlen=,mb_strlen($unicodeValues, utf8); echo \n; echo The string length with strlen=,strlen($unicodeValues); ?>

  10. เกิดอะไรขึ้นถ้าใช้ ++ operator กับค่าสตริงใน PHP

    หากคุณลองใช้ ++ operator กับค่าสตริง มันจะเพิ่มค่าตัวอักษรตัวสุดท้ายขึ้น 1 และพิมพ์ค่า ASCII โค้ด PHP ดังนี้ - ตัวอย่าง <!DOCTYPE html> <html> <body> <?php $values = John; echo The string modified value is=,++$values,; $values1=10.5; echo The string increment

  11. PHP แสดงค่าอาร์เรย์พร้อมข้อความ "even" สำหรับค่า index คู่

    สำหรับเรื่องนี้ คุณสามารถใช้ for loop ร่วมกับเงื่อนไขบางอย่าง โค้ด PHP ดังนี้ - ตัวอย่าง <!DOCTYPE html> <html> <body> <?php $arrayList = []; for ($counter = 0; $counter < 5; $counter++) { ($counter%2) ? ($arrayList[] = $counter) : ($arrayList[] = Even);

  12. PHP ดึงตัวเลขหลัง Hyphen ตัวสุดท้าย

    สมมติสตริงต่อไปนี้รวม hyphen และตัวเลข - John-45-98-78-7898906756 เพื่อดึงตัวเลขหลัง - คือ hyphen ใช้ explode() พร้อมพารามิเตอร์ - และ $yourVariableName โค้ด PHP ดังนี้ - ตัวอย่าง <!DOCTYPE html> <html> <body> <?php $values = John-45-98-78-7898906756; $values = explode

  13. PHP การเพิ่มค่าเข้า Associative Array

    เพื่อเพิ่มค่าเข้า associative array ให้ใช้ brackets [] [] ก่อนอื่นสร้าง associative array - US ); โค้ด PHP สำหรับแทรกค่าดังนี้ - ตัวอย่าง US ); $all_details[studentDetails][] = $details; print_r($all_details); ?> </body> </html> ผลลัพธ์ US ) ) )

  14. ความแตกต่างระหว่าง For และ Foreach ใน PHP

    ในบทความนี้ เราจะทำความเข้าใจความแตกต่างระหว่างลูป for และ foreach ใน PHP - ลูป for เป็น iterative loop ที่ทำซ้ำชุดโค้ดจนกว่าเงื่อนไขที่ระบุจะเป็นจริง ใช้ execute ชุดโค้ดสำหรับจำนวนครั้งที่กำหนด ที่นี่ จำนวนครั้งคือตัวแปร iterator Syntax: for( initialization; condition; increment/decrement ) {

  15. Group Use Declarations ใน PHP 7

    ใน PHP 7 Group Use declaration อ่านง่ายกว่า และสามารถนำเข้า classes, constants, และ functions ได้อย่างง่ายดายจาก namespace เดียวกันGroup Use declaration ใช้สำหรับนำเข้าโครงสร้างหลายอย่างจาก namespace และลด verbosity ลงได้มากในกรณีส่วนใหญ่ ยังช่วยระบุ multiple imported entities ที่อยู่ใน module เดียว

  16. ประเภทของ Group Use Declarations ใน PHP 7

    PHP 7 ใช้ Group Use declarations 3 ประเภทที่แตกต่างกัน - Non-mixed-use declarations Mixed-use declarations Compound use declarations Non-mixed-use declarations: Non-mixed-use declaration หมายถึงเราไม่ใช้คลาส ฟังก์ชัน และคอนสตรัคต์ในคำสั่งเดียว หรือเราสามารถพูดได้ว่าเมื่อเราประกาศคลาส ฟังก์ชัน และค

  17. Generator Return Expressions ใน PHP 7

    ใน PHP เวอร์ชันก่อนหน้า ฟังก์ชัน generator ไม่สามารถคืนค่านิพจน์ได้ แต่ตั้งแต่ PHP 5.5 generator return expression ถูกเพิ่มเข้ามาในที่มีอยู่แล้ว ด้วยการใช้ generator return expressions การใช้คำสั่ง return ภายใน generator จะง่ายขึ้น และยังคืนค่าของนิพจน์สุดท้าย ด้วยการใช้ generator return expression

  18. Generator Delegation ใน PHP 7

    แนวคิดของ generator ไม่ได้ใหม่ใน PHP 7 เพราะมีอยู่ในเวอร์ชันก่อนหน้าแล้ว ด้วย generators การ implement จะง่ายขึ้นโดยไม่มี overhead ของการ implement คลาสที่ implements iterator interface ด้วยความช่วยเหลือของ generator เราสามารถเขียนโค้ด foreach ได้โดยไม่ต้องใช้อาร์เรย์ในหน่วยความจำ มันยังช่วยกำจัดข้อ

Total 1286 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:59/65  20-คอมพิวเตอร์/Page Goto:1 53 54 55 56 57 58 59 60 61 62 63 64 65