Catalog / PHP Cheatsheet
PHP Cheatsheet
A comprehensive cheat sheet covering essential PHP syntax, functions, and best practices for web development.
Core Syntax & Data Types
Basic Syntax
Opening tag |
|
Closing tag |
|
Statement terminator |
|
Comments (single-line) |
|
Comments (multi-line) |
|
Echoing output |
|
Data Types
Scalar Types:
|
Compound Types:
|
Special Types:
|
Variable Declaration
Declaration |
|
Example |
|
Operators & Control Structures
Operators
Arithmetic |
|
Assignment |
|
Comparison |
|
Increment/Decrement |
|
Logical |
|
String |
|
Control Structures
Conditional Statements:
|
Switch Statement:
|
Loops:
|
Functions & Arrays
Functions
Definition |
|
Calling a function |
|
Example with default argument |
|
Arrays
Indexed Arrays:
|
Associative Arrays:
|
Multidimensional Arrays:
|
Array Functions
|
Returns the number of elements in an array. |
|
Adds one or more elements to the end of an array. |
|
Removes the last element from an array. |
|
Removes the first element from an array. |
|
Adds one or more elements to the beginning of an array. |
|
Merges one or more arrays into one array. |
|
Checks if a value exists in an array. |
Classes & Objects
Class Definition
|
Visibility:
|
Object Instantiation
Creating an object |
|
Accessing properties and methods |
|
Constructors & Destructors
Constructor:
|
Destructor:
|
Inheritance
Extending a class |
|
Overriding methods |
A child class can override methods of the parent class. |