Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP
PHP
  1. PHP ตรวจสอบ Special Characters ใน String

    ตัวอย่างโค้ด<?php function check_string($my_string) { $regex = preg_match([@_!#$%^&*()<>?/|}{~:], $my_string); if ($regex) { print(String has been accepted); } else { print(String has not been accepted); } } $my_string = This_is_$_sample!; check_string($my_string)

  2. PHP ผลรวมตัวเลขในตัวเลข (Sum of Digits)

    ตัวอย่างโค้ด<?php function sum_of_digits($my_num) { $sum = 0; for ($i = 0; $i < strlen($my_num); $i++) { $sum += $my_num[$i]; } return $sum; } $my_num = 65; echo The sum of digits is . sum_of_digits($my_num); ?> ผลลัพธ์The sum of digits is 11 คำอธิบาย รับ Input เป็

  3. PHP นับจำนวนตัวอักษรใน String

    ตัวอย่างโค้ด<?php $my_string = Hi there, this is a sample ; $len = mb_strlen($my_string); echo The number of characters in the string is $len; ?> ผลลัพธ์The number of characters in the string is 27 คำอธิบาย mb_strlen() - Multi-byte Safe นับ Characters (รวม Spaces) strlen() - นับ Bytes (ไม่เ

  4. PHP หาคำแรกของประโยค

    ตัวอย่างโค้ด<?php $my_string = Hi there, this is a sample statement; echo The first word of the string is . strtok($my_string, ); ?> ผลลัพธ์The first word of the string is Hi คำอธิบาย strtok($string, $delimiter) ตัด String ด้วย Delimiter ครั้งแรกส่ง String 全体 ครั้งต่อไปส่งแค่ Delimiter คื

  5. PHP ลบ Element จาก Array ด้วย unset()

    ตัวอย่างโค้ด<?php $my_array = [Joe, Ben, Mary, Barun, Sona, Mona]; unset($my_array[4]); echo After deleting the element, the array is\n; print_r($my_array); ?> ผลลัพธ์ Mona ) คำอธิบาย Array Index เริ่มที่ 0 → Index 4 คือ Element ตัวที่ 5 (Sona) unset() ลบ Element และ Key ออกจาก Array Key ไ

  6. PHP หาค่าต่ำสุดใน Array

    ตัวอย่างโค้ด<?php function get_min_value($my_array) { $n = count($my_array); $min_val = $my_array[0]; for ($i = 1; $i $my_array[$i]) { $min_val = $my_array[$i]; } } return $min_val; } $my_array = [56, 78, 91, 44, 0, 11]; echo The lowest value of the array

  7. PHP เปลี่ยนรูปแบบวันที่ (Date Format)

    ตัวอย่างโค้ด<?php function string_convert($my_date) { $sec = strtotime($my_date); $my_date = date(Y-m-d H:i, $sec); $my_date = $my_date . :00; echo $my_date; } $my_date = 23/11/2020 11:59 PM; string_convert($my_date); ?> ผลลัพธ์1970-01-01 00:00:00 ปัญหาและการแก้ไขปัญหา: รูปแ

  8. PHP ตรวจสอบเลขใน Infinite Series

    ตัวอย่างโค้ด 0 && ($n - $m) % $o == 0) return true; return false; } $m = 3; $n = 5; $o = 9; if (contains_val($m, $n, $o)) { echo The number is present in the infinite series; } else { echo The number is not present in the infinite series; } ?> ผลลัพธ์The number is not present in th

  9. PHP หาค่าสูงสุดใน Array

    ตัวอย่างโค้ด<?php function get_max_value($my_array) { $n = count($my_array); $max_val = $my_array[0]; for ($i = 1; $i < $n; $i++) { if ($max_val < $my_array[$i]) { $max_val = $my_array[$i]; } } return $max_val; } $my_array = [56, 78, 91, 44, 0, 11]

  10. คำสั่ง break ใน PHP

    บทนำbreak เป็น Looping Control Keyword ใน PHP เมื่อโปรแกรมเจอ break ภายใน while, do-while, for, foreach หรือ switch จะข้าม Statement ที่เหลือใน Loop/Switch ไปทำงาน Statement ถัดไป Syntaxwhile (expr) { ... if (expr1) break; ... } ตัวอย่าง: ออกจาก Loop ด้วยเงื่อนไขWhile Loop อ่าน Input จ

  11. Array Operators ใน PHP

    บทนำPHP กำหนด Operators สำหรับ Array Data Types ดังนี้: SymbolExampleNameResult +$a + $bUnionUnion ของ $a และ $b ==$a == $bEqualityTRUE ถ้า Key/Value Pairs เหมือนกัน ===$a === $bIdentityTRUE ถ้า Key/Value Pairs เหมือนกัน ลำดับเดียวกัน Type เดียวกัน !=$a != $bInequalityTRUE ถ้า $a ไม่เท่ากับ $b &l

  12. คำสั่ง declare ใน PHP

    บทนำSyntax ของ declare Statement ใน PHP คล้าย Flow Control Structures (while, for, foreach) ใช้กำหนด Directives สำหรับ Block ของโค้ด Syntaxdeclare (directive) { statement1; statement2; ... } มี 3 Directives: ticks, encoding, strict_types 1. Ticks DirectiveTick = Event ที่เกิดทุก N Sta

  13. การขยาย Exception (Extending Exceptions) ใน PHP

    บทนำClass Exception Implement Throwable Interface เป็น Base Class ของทุก Exception Classes (Predefined และ User-defined) Exception Class กำหนด Methods Final (Non-overridable) สำหรับ Throwable Interface และ __toString() ที่ Override ได้เพื่อ String Representation Exception Methods Methodคำอธิบาย f

  14. Exception Handling กับ Finally ใน PHP

    บทนำโค้ดใน Finally Block จะ Execute เสมอ ไม่ว่าจะมี Exception ใน Try Block หรือไม่ Block นี้อยู่หลัง Catch Block หรือแทน Catch Block ก็ได้ 1. Catch และ Finally ทั้งคู่ถ้ามี Exceptionใน Try → ทั้ง Catch และ Finally รัน ถ้าไม่มี Exception → แค่ Finally รัน: getMessage(), \n; } finally { echo Thi

  15. การปฏิสัมพันธ์ระหว่าง Finally และ Return ใน PHP

    บทนำพฤติกรรมพิเศษของ Finally Block เมื่อ Try หรือ Catch (หรือทั้งคู่) มี Return Statement ปกติ Return จะคืน Control กลับไปยัง Caller แต่ใน Function ที่มี Try/Catch/Finally พร้อม Return Statement ใน Finally จะ Execute ก่อน Return ตัวอย่างFunction div() มี Try-Catch-Finally Try Block Return ผลหาร Cat

  16. Errors ใน PHP 7

    บทนำก่อน Version 7 PHP รายงาน Errors ตาม Type ต่างๆ PHP 7 เปลี่ยน Mechanism - โยน Error Exceptions แทน Traditional Error Reporting ถ้า Error Exceptions ไม่ถูกจับ จะรายงาน Fatal Error เหมือนเดิม PHP Error Hierarchy เริ่มจาก Interface Throwable Predefined Errors (ArithmeticError, AssertionError, Comp

Total 1286 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:49/65  20-คอมพิวเตอร์/Page Goto:1 43 44 45 46 47 48 49 50 51 52 53 54 55