1. Variables
$variable = 'value'; // string variable
$variable = 10; // integer variable
$variable = 20.5; // floating-point variable
2. Data Types
string, integer, float, boolean, array, object, NULL
3. Operators
+, -, \*, /, %, ==, !=, >, <, >=, <=, &&, ||, !
4. Control Structures
if (condition) { code }
if (condition) { code } else { code }
switch (expression) { case value: code; break; }
for (init; condition; increment) { code }
while (condition) { code }
do { code } while (condition);
5. Loops
for ($i = 0; $i < 10; $i++) { code }
while ($i < 10) { code; $i++; }
do { code; $i++; } while ($i < 10);
6. Arrays
$fruits = array('apple', 'banana', 'orange');
$fruits = ['apple', 'banana', 'orange']; // shorthand syntax
7. Functions
function add($a, $b) { return $a + $b; }
function greet($name) { echo "Hello, $name!"; }
8. Classes
class Person {
private $name;
public function __construct($name) { $this->name = $name; }
public function display() { echo "Name: $this->name"; }
}
9. Objects
$person = new Person('John Doe');
$person->display(); // prints "Name: John Doe"
10. Inheritance
class Animal {
public function sound() { echo "The animal makes a sound."; }
}
class Dog extends Animal {
public function sound() { echo "The dog barks."; }
}
11. Polymorphism
class Animal {
public function sound() { echo "The animal makes a sound."; }
}
class Dog extends Animal {
public function sound() { echo "The dog barks."; }
}
$animal = new Dog();
$animal->sound(); // prints "The dog barks."
12. Encapsulation
class Person {
private $name;
public function __construct($name) { $this->name = $name; }
public function getName() { return $this->name; }
}
13. Abstraction
abstract class Animal {
abstract public function sound();
}
class Dog extends Animal {
public function sound() { echo "The dog barks."; }
}
14. Interface
interface Printable {
public function print();
}
class Document implements Printable {
public function print() { echo "Printing document..."; }
}
15. Exception Handling
try { code } catch (Exception $e) { code }
16. File Input/Output
$file = fopen('example.txt', 'r');
fscanf($file, '%d', $x);
17. Networking
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
18. Multithreading
class MyThread extends Thread {
public function run() { /* code */ }
}
$thread = new MyThread();
$thread->start();
19. Lambda Functions
$add = function($a, $b) { return $a + $b; };
20. Namespaces
namespace MyNamespace;
class MyClass { }
21. Superglobals
$_GET, $_POST, $_SESSION, $_COOKIE, $_FILES, $_SERVER
22. Type Hinting
function add(int $a, int $b): int { return $a + $b; }
23. Null Coalescing Operator
$value = $input ?? 'default';
24. Ternary Operator
$result = ($condition) ? 'true' : 'false';
25. Array Functions
array_push($array, $value);
array_pop($array);
26. String Functions
strlen($string);
strpos($string, 'search');
27. Date and Time
$date = new DateTime();
echo $date->format('Y-m-d H:i:s');
28. JSON Handling
$json = json_encode($data);
$data = json_decode($json);
29. Sessions
session_start();
$_SESSION['key'] = 'value';
30. Cookies
setcookie('name', 'value', time() + 3600);
31. File Upload
if ($_FILES['file']['error'] == UPLOAD_ERR_OK) { /* code */ }
32. cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com');
curl_exec($ch);
curl_close($ch);
33. Composer
require 'vendor/autoload.php';
34. PDO
$pdo = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
35. Prepared Statements
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id');
$stmt->execute(['id' => $id]);
36. Error Handling
set_error_handler(function($errno, $errstr) { /* code */ });
37. Autoloading
spl_autoload_register(function ($class) { include $class . '.php'; });
38. Traits
trait MyTrait { public function myMethod() { /* code */ } }
class MyClass { use MyTrait; }
39. Generators
function myGenerator() { yield 1; yield 2; }
foreach (myGenerator() as $value) { /* code */ }
40. Reflection
$reflection = new ReflectionClass('MyClass');
$methods = $reflection->getMethods();
41. Cloning Objects
$clone = clone $original;
42. Magic Methods
public function __get($name) { /* code */ }
public function __set($name, $value) { /* code */ }
43. Static Methods
class MyClass {
public static function myStaticMethod() { /* code */ }
}
44. Static Properties
class MyClass {
public static $myStaticProperty;
}
45. Constants
define ('MY_CONSTANT', 'value');
class MyClass {
const MY_CLASS_CONSTANT = 'value';
}
46. Variable Variables
$varName = 'hello';
$$varName = 'world'; // $hello is now 'world'
47. Array Destructuring
[$a, $b] = [1, 2];
48. Spread Operator
$array1 = [1, 2];
$array2 = [...$array1, 3, 4];
49. Nullsafe Operator
$result = $object?->method();
50. Match Expression
$result = match($value) {
1 => 'one',
2 => 'two',
default => 'other',
};
51. Array Filter
$filtered = array_filter($array, fn($value) => $value > 0);
52. Array Map
$squared = array_map(fn($value) => $value ** 2, $array);
53. Array Reduce
$sum = array_reduce($array, fn($carry, $item) => $carry + $item, 0);
54. Array Slice
$sliced = array_slice($array, 1, 2);
55. Array Merge
$merged = array_merge($array1, $array2);
56. Array Unique
$unique = array_unique($array);
57. Array Keys
$keys = array_keys($array);
58. Array Values
$values = array_values($array);
59. Array Count
$count = count($array);
60. Array Push
array_push($array, $value);
61. Array Pop
$value = array_pop($array);
62. Array Shift
$value = array_shift($array);
63. Array Unshift
array_unshift($array, $value);
64. Array Fill
$filled = array_fill(0, 5, 'value');
65. Array Chunk
$chunks = array_chunk($array, 2);
66. Array Column
$column = array_column($array, 'column_name');
67. Array Combine
$combined = array_combine($keys, $values);
68. Array Diff
$difference = array_diff($array1, $array2);
69. Array Intersect
$intersection = array_intersect($array1, $array2);
70. Array Search
$key = array_search('value', $array);
71. Array Splice
array_splice($array, 1, 2);
72. Array Reverse
$reversed = array_reverse($array);
73. Array Sort
sort($array);
74. Array Shuffle
shuffle($array);
75. Array Map with Keys
$mapped = array_map(fn($value, $key) => "$key: $value", $array, array_keys($array));
76. Array Filter with Keys
$filtered = array_filter($array, fn($value, $key) => $key % 2 === 0, ARRAY_FILTER_USE_BOTH);
77. Array Reduce with Keys
$sum = array_reduce($array, fn($carry, $item) => $carry + $item, 0);
78. Array Count Values
$counts = array_count_values($array);
79. Array Pad
$padded = array_pad($array, 5, 'value');
80. Array Flip
$flipped = array_flip($array);
81. Array Is Array
$isArray = is_array($array);
82. Array Keys Exists
$exists = array_key_exists('key', $array);
83. Array Values Exists
$exists = in_array('value', $array);
84. Array Diff Key
$difference = array_diff_key($array1, $array2);
85. Array Intersect Key
$intersection = array_intersect_key($array1, $array2);
86. Array Merge Recursive
$merged = array_merge_recursive($array1, $array2);
87. Array Replace
$replaced = array_replace($array1, $array2);
88. Array Unique Recursive
$unique = array_unique($array, SORT_REGULAR);
89. Array Column with Objects
$names = array_column($arrayOfObjects, 'name');
90. Array Group By
$grouped = [];
foreach ($array as $item) {
$grouped[$item['key']][] = $item;
}
91. Array Random
$randomValue = $array[array_rand($array)];
92. Array Sum
$sum = array_sum($array);
93. Array Product
$product = array_product($array);
94. Array Diff Ukey
$difference = array_udiff_uassoc($array1, $array2, fn($a, $b) => $a - $b, fn($a, $b) => $a - $b);
95. Array Intersect Ukey
$intersection = array_uintersect_uassoc($array1, $array2, fn($a, $b) => $a - $b, fn($a, $b) => $a - $b);
96. Array Map with Keys
$mapped = array_map(fn($value, $key) => "$key: $value", $array, array_keys($array));
97. Array Filter with Keys
$filtered = array_filter($array, fn($value, $key) => $key % 2 === 0, ARRAY_FILTER_USE_BOTH);
98. Array Reduce with Keys
$sum = array_reduce($array, fn($carry, $item) => $carry + $item, 0);
99. Array Count Values
$counts = array_count_values($array);
100. Array Pad
$padded = array_pad($array, 5, 'value');