ชีตสรุป PHP
ข้อมูลอ้างอิง PHP 8.3+ ที่ค้นหาและพิมพ์ได้ — ไวยากรณ์ สตริง อาร์เรย์ ฟังก์ชัน คลาส enums แอตทริบิวต์ และฟีเจอร์สมัยใหม่ ฟรี
Basics & types
10declare(strict_types=1);
$x = 1;
const MAX = 100;
gettype($x)
(int) $x
is_int($x)
int|string $x
?string $x
$a ?? 'default'
$a ??= 'default'
Strings
11"Hello $name"
'literal $x'
$a . $b
strlen($s)
str_contains($s, 'a')
str_starts_with($s, 'a')
substr($s, 0, 3)
str_replace('a', 'b', $s)
explode(',', $s)
sprintf('%05.2f', $n)
trim($s)
Arrays
11$a = [1, 2, 3];
$a = ['k' => 'v'];
array_map(fn($x) => $x * 2, $a)
array_filter($a, fn($x) => $x > 0)
array_reduce($a, $fn, 0)
in_array($v, $a, true)
array_keys($a)
array_merge($a, $b)
[...$a, ...$b]
count($a)
[$x, $y] = $a;
Functions
9function f(int $a): int {}
function f(int $a = 1) {}
function f(int ...$nums) {}
f(...$args)
f(name: 'Sam', age: 30)
$fn = fn($x) => $x + 1;
function () use ($x) {}
$fn = strlen(...);
function f(): never {}
Control flow
9if ($a) {} elseif ($b) {} else {}
$a ? $b : $c
$a ?: $b
match ($x) { 1, 2 => 'a', default => 'b' }
switch ($x) { case 1: break; }
foreach ($a as $k => $v) {}
for ($i = 0; $i < 10; $i++) {}
while ($cond) {}
break / continue
Classes & OOP
10class A extends B implements C {}
public function __construct(private int $id) {}
public readonly string $name;
public function f(): static {}
static::create()
$obj?->method()
abstract class A {}
trait T {} use T;
$obj instanceof A
A::class
Enums
9enum Status { case Active; case Draft; }
enum Status: string { case A = 'a'; }
Status::Active
Status::from('a')
Status::tryFrom('x')
Status::cases()
$status->value
$status->name
enum E { public function label() {} }
Error handling
9try {} catch (Throwable $e) {}
catch (TypeError | ValueError $e)
catch (Exception)
finally {}
throw new RuntimeException('x')
throw $e;
$x = $v ?? throw new Error();
$e->getMessage()
$e->getPrevious()
Attributes & modern
9#[Attribute] class Route {}
#[Route('/home')]
new ReflectionClass($x)
$ref->getAttributes()
json_encode($data)
json_decode($s, true)
array_is_list($a)
str_word_count($s)
$obj::class
ไม่มีรายการที่ตรงกับ “:q”
เกี่ยวกับ ชีตสรุป PHP
เอกสารสรุป PHP นี้ย่อ PHP สมัยใหม่ให้อยู่ในหน้าเดียวที่ค้นหาได้: พื้นฐานและชนิดข้อมูล string อาร์เรย์ ฟังก์ชัน การควบคุมโฟลว์ คลาสและ OOP enum การจัดการข้อผิดพลาด และ attribute กับฟีเจอร์สมัยใหม่อื่น ๆ ทุกแถวเป็นสนิปเป็ตที่รันได้พร้อมคำอธิบายภาษาอังกฤษง่าย ๆ
มันมุ่งเป้าไปที่ PHP 8.3+ ดังนั้นคุณจะพบฟีเจอร์ที่กำหนดนิยาม PHP ยุคปัจจุบัน — enum, readonly property, constructor property promotion, named argument, match expression, arrow function, nullsafe call และ attribute — ควบคู่ไปกับฟังก์ชัน string และอาร์เรย์ที่ใช้ทุกวัน
หน้านี้ฟรีและทำงานฝั่ง client ทั้งหมด: การค้นหากรองแถวขณะที่คุณพิมพ์ เมนูส่วนที่ติดอยู่บนหน้าพาคุณไปมาในเอกสาร คลิกครั้งเดียวเพื่อคัดลอกสนิปเป็ตใด ๆ และปุ่มพิมพ์จะเปลี่ยนมันเป็นเอกสารอ้างอิง PHP บนกระดาษ
วิธีใช้ ชีตสรุป PHP
- ดูสารบัญ — ตั้งแต่ Basics & types ไปจนถึง Enums, Error handling และ Attributes & modern
- พิมพ์ชื่อฟังก์ชันหรือคำสำคัญลงในกล่องค้นหาเพื่อกรองเอกสารทั้งหมดทันที
- กระโดดไปยังส่วนอย่าง Classes & OOP ผ่านแถบนำทางด้านข้างที่ติดอยู่บนหน้า
- คลิกสนิปเป็ตใด ๆ หรือไอคอนคัดลอกของมันเพื่อคัดลอกโค้ด PHP ไปยังคลิปบอร์ดของคุณ
- กด Print หากคุณต้องการเอกสารอ้างอิงทั้งหมดบนกระดาษ