Όλα τα εργαλεία
Δωρεάν

Μια αναζητήσιμη, εκτυπώσιμη αναφορά PHP 8.3+ — σύνταξη, strings, arrays, συναρτήσεις, κλάσεις, enums, attributes και σύγχρονα χαρακτηριστικά. Δωρεάν.

Basics & types

10
declare(strict_types=1);
Enforce strict scalar type checks
$x = 1;
Variables start with a dollar sign
const MAX = 100;
Compile-time constant
gettype($x)
Get the type of a value
(int) $x
Cast to an integer
is_int($x)
Type-check helper (is_string, ...)
int|string $x
Union type declaration
?string $x
Nullable type (string or null)
$a ?? 'default'
Null coalescing operator
$a ??= 'default'
Assign only if null

Strings

11
"Hello $name"
Double quotes interpolate variables
'literal $x'
Single quotes are literal
$a . $b
Concatenate strings
strlen($s)
Byte length of a string
str_contains($s, 'a')
Check for a substring
str_starts_with($s, 'a')
Check the prefix
substr($s, 0, 3)
Extract part of a string
str_replace('a', 'b', $s)
Replace all occurrences
explode(',', $s)
Split into an array
sprintf('%05.2f', $n)
Formatted string output
trim($s)
Strip surrounding whitespace

Arrays

11
$a = [1, 2, 3];
Indexed array literal
$a = ['k' => 'v'];
Associative array
array_map(fn($x) => $x * 2, $a)
Transform each element
array_filter($a, fn($x) => $x > 0)
Keep matching elements
array_reduce($a, $fn, 0)
Reduce to a single value
in_array($v, $a, true)
Strict value check
array_keys($a)
Get all keys
array_merge($a, $b)
Merge arrays
[...$a, ...$b]
Spread/merge arrays
count($a)
Number of elements
[$x, $y] = $a;
Array destructuring

Functions

9
function f(int $a): int {}
Typed parameters and return
function f(int $a = 1) {}
Default parameter value
function f(int ...$nums) {}
Variadic parameters
f(...$args)
Spread arguments
f(name: 'Sam', age: 30)
Named arguments
$fn = fn($x) => $x + 1;
Arrow function (auto-captures scope)
function () use ($x) {}
Closure capturing a variable
$fn = strlen(...);
First-class callable syntax
function f(): never {}
Never returns (throws or exits)

Control flow

9
if ($a) {} elseif ($b) {} else {}
Conditional branches
$a ? $b : $c
Ternary expression
$a ?: $b
Short ternary (falsy fallback)
match ($x) { 1, 2 => 'a', default => 'b' }
Strict, expression-based match
switch ($x) { case 1: break; }
Loose multi-way branch
foreach ($a as $k => $v) {}
Iterate keys and values
for ($i = 0; $i < 10; $i++) {}
Counted loop
while ($cond) {}
Loop while a condition holds
break / continue
Exit or skip a loop iteration

Classes & OOP

10
class A extends B implements C {}
Inheritance and interfaces
public function __construct(private int $id) {}
Constructor property promotion
public readonly string $name;
Immutable after initialization
public function f(): static {}
Return the late-bound type
static::create()
Late static binding
$obj?->method()
Null-safe method call
abstract class A {}
Cannot be instantiated directly
trait T {} use T;
Reusable horizontal code
$obj instanceof A
Type check at runtime
A::class
Fully-qualified class name string

Enums

9
enum Status { case Active; case Draft; }
Pure enumeration
enum Status: string { case A = 'a'; }
Backed enum (string/int)
Status::Active
Reference an enum case
Status::from('a')
Build from a backing value
Status::tryFrom('x')
Returns null if invalid
Status::cases()
Array of all cases
$status->value
Backing value of a case
$status->name
Name of the case
enum E { public function label() {} }
Enums can have methods

Error handling

9
try {} catch (Throwable $e) {}
Catch errors and exceptions
catch (TypeError | ValueError $e)
Catch multiple types
catch (Exception)
Non-capturing catch (no variable)
finally {}
Always runs after try/catch
throw new RuntimeException('x')
Throw an exception
throw $e;
Re-throw the caught exception
$x = $v ?? throw new Error();
Throw as an expression
$e->getMessage()
Read the error message
$e->getPrevious()
Get the chained exception

Attributes & modern

9
#[Attribute] class Route {}
Declare a custom attribute
#[Route('/home')]
Apply an attribute to a target
new ReflectionClass($x)
Inspect a class via reflection
$ref->getAttributes()
Read declared attributes
json_encode($data)
Serialize to JSON
json_decode($s, true)
Decode JSON to an array
array_is_list($a)
True if keys are 0..n in order
str_word_count($s)
Count words in a string
$obj::class
Class name from an instance

Καμία καταχώριση δεν ταιριάζει με «:q».


Σχετικά με το Συνοπτικός οδηγός PHP

Αυτό το cheat sheet PHP συμπυκνώνει τη σύγχρονη PHP σε μία αναζητήσιμη σελίδα: βασικά και τύπους, συμβολοσειρές, πίνακες, συναρτήσεις, ροή ελέγχου, κλάσεις και OOP, enums, χειρισμό σφαλμάτων, και attributes και άλλα σύγχρονα χαρακτηριστικά. Κάθε γραμμή είναι ένα εκτελέσιμο απόσπασμα με μια περιγραφή σε απλή γλώσσα.

Στοχεύει στην PHP 8.3+, οπότε θα βρείτε τα χαρακτηριστικά που ορίζουν τη σημερινή PHP — enums, readonly ιδιότητες, constructor property promotion, ονομασμένα ορίσματα, εκφράσεις match, arrow functions, nullsafe κλήσεις και attributes — δίπλα στις καθημερινές συναρτήσεις συμβολοσειρών και πινάκων που χρησιμοποιείτε συνεχώς.

Η σελίδα είναι δωρεάν και πλήρως πλευράς-πελάτη: η αναζήτηση φιλτράρει τις γραμμές καθώς πληκτρολογείτε, το κολλημένο μενού ενοτήτων σας μεταφέρει γύρω από το φύλλο, ένα κλικ αντιγράφει οποιοδήποτε απόσπασμα, και ένα κουμπί εκτύπωσης το μετατρέπει σε χάρτινη αναφορά PHP.

Πώς να χρησιμοποιήσετε το Συνοπτικός οδηγός PHP

  1. Σαρώστε τον πίνακα περιεχομένων — από Βασικά & τύποι έως Enums, Χειρισμός σφαλμάτων και Attributes & σύγχρονα.
  2. Πληκτρολογήστε ένα όνομα συνάρτησης ή λέξη-κλειδί στο πλαίσιο αναζήτησης για να φιλτράρετε ολόκληρο το φύλλο ακαριαία.
  3. Μεταβείτε σε μια ενότητα όπως Κλάσεις & OOP μέσω της κολλημένης πλευρικής πλοήγησης.
  4. Κάντε κλικ σε οποιοδήποτε απόσπασμα ή στο εικονίδιο αντιγραφής του για να αντιγράψετε τον κώδικα PHP στο πρόχειρό σας.
  5. Πατήστε Εκτύπωση αν θέλετε ολόκληρη την αναφορά σε χαρτί.

Συχνές ερωτήσεις

Είναι γραμμένο για PHP 8.3 και νεότερες. Οι ενότητες για enums, attributes και σύγχρονα χαρακτηριστικά καλύπτουν readonly ιδιότητες, constructor promotion, εκφράσεις match, ονομασμένα ορίσματα και nullsafe κλήσεις επιπλέον της κλασικής σύνταξης.

Εννέα ενότητες: βασικά και τύποι, συμβολοσειρές, πίνακες, συναρτήσεις, ροή ελέγχου, κλάσεις και OOP, enums, χειρισμός σφαλμάτων, και attributes συν σύγχρονα χαρακτηριστικά — τα μέρη της PHP που χρησιμοποιείτε καθημερινά σε πραγματικά έργα.

Χρησιμοποιήστε το πλαίσιο αναζήτησης στην κορυφή. Φιλτράρει κάθε γραμμή ζωντανά σε όλες τις ενότητες και εμφανίζει έναν μετρητή αντιστοιχιών, οπότε πληκτρολογώντας κάτι σαν array_map περιορίζει το φύλλο στα σχετικά αποσπάσματα ακαριαία.

Ναι. Κάντε κλικ στον ίδιο τον κώδικα ή στο εικονίδιο αντιγραφής κατά την επαφή με το ποντίκι και το απόσπασμα καταλήγει στο πρόχειρό σας, επιβεβαιωμένο από μια σύντομη λάμψη «Αντιγράφηκε!».

Ναι, εντελώς δωρεάν. Αποδίδεται στο πρόγραμμα περιήγησής σας, δεν χρειάζεται λογαριασμό και μπορεί να εκτυπωθεί όσο συχνά θέλετε.

Κοινοποίηση

Δημοφιλείς αναζητήσεις
php cheat sheet php syntax reference php array functions php string functions php enums example php 8 attributes php oop cheat sheet php try catch example
Χρειάζεστε βοήθεια;
Βρήκατε πρόβλημα με αυτό το εργαλείο; Ενημερώστε μας.
Αναφορά προβλήματος

Προσθέστε αυτό το δωρεάν εργαλείο στον δικό σας ιστότοπο — αντιγράψτε και επικολλήστε τον παρακάτω κώδικα.