PHP Cheat Sheet
PHP is an incredibly versatile language that is used to power a wide variety of websites and web applications. Whether you’re just beginning to learn PHP or you’re looking for a quick reference, here is a comprehensive PHP cheat sheet to help you out.
Variables:
• $variableName — to declare a variable
• echo $variableName — to print a variable
• $variableName = “string” — to assign a value to a variable
Data Types:
• Strings — data surrounded by single (‘) or double (“) quotes
• Integers — whole numbers
• Floats — numbers with decimals
• Booleans — true/false values
• Arrays — lists of data
• Objects — complex data structures
Arithmetic Operators:
• + — addition
• — — subtraction
• * — multiplication
• / — division
• % — modulus
Logical Operators:
• && — and
• || — or
• ! — not
Comparison Operators:
• == — equal to
• != — not equal to
• < — less than
• > — greater than
• <= — less than or equal to
• >= — greater than or equal to
Control Structures:
• if/else — to execute a block of code based on a condition
• switch — to execute code based on multiple conditions
• for — to execute a block of code a certain number of times
• while — to execute a block of code while a condition is true
• foreach — to loop through an array
Functions:
• functionName() — to declare a function
• functionName(parameter1, parameter2, …) — to pass parameters to a function
• return — to return a value from a function
Other PHP Syntax:
• require/include — to include a file
• $_GET — to retrieve data from a form
• $_POST — to send data from a form
• $_COOKIE — to set/retrieve data from a cookie
• $_SESSION — to store data across multiple pages
Hopefully, this PHP cheat sheet has been a helpful reference for you. If you’re looking for more comprehensive PHP tutorials, be sure to check out our library of PHP tutorials.
👉 Follow us on Twitter!
Happy Hacking!