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 cheat sheet आधुनिक PHP को एक searchable page में समेटता है: basics और types, strings, arrays, functions, control flow, classes और OOP, enums, error handling, और attributes व अन्य आधुनिक सुविधाएँ। हर row एक चलने योग्य snippet है जिसमें सादे शब्दों में विवरण है।
यह PHP 8.3+ को लक्षित करता है, इसलिए आपको वे सुविधाएँ मिलेंगी जो वर्तमान PHP को परिभाषित करती हैं — enums, readonly properties, constructor property promotion, named arguments, match expressions, arrow functions, nullsafe calls और attributes — साथ ही वे रोज़मर्रा के string और array functions जिनका आप लगातार उपयोग करते हैं।
page मुफ़्त और पूरी तरह client-side है: search जैसे ही आप टाइप करते हैं rows को फ़िल्टर करता है, sticky section menu आपको sheet में इधर-उधर ले जाता है, एक क्लिक किसी भी snippet को कॉपी कर देता है, और एक print बटन इसे एक पेपर PHP संदर्भ में बदल देता है।
PHP चीट शीट का उपयोग कैसे करें
- table of contents देखें — Basics & types से लेकर Enums, Error handling और Attributes & modern तक।
- पूरी sheet को तुरंत फ़िल्टर करने के लिए search box में एक function name या keyword टाइप करें।
- sticky sidebar navigation के ज़रिए Classes & OOP जैसे किसी section पर जाएँ।
- PHP कोड को क्लिपबोर्ड पर कॉपी करने के लिए किसी भी snippet या उसके copy icon पर क्लिक करें।
- यदि आप पूरा संदर्भ कागज़ पर चाहते हैं तो Print दबाएँ।