Syntax
PHP is a server-side scripting language, which means that PHP scripts are executed on the server and the result is sent to the client as plain HTML.
PHP Tags
PHP scripts are always enclosed within the PHP opening and closing tags. The default syntax for these tags is as follows:
Everything outside these tags is considered plain HTML (or other types of code, like JavaScript or CSS), and everything inside these tags is treated as PHP code.
Comments
Comments are a useful way to leave notes for yourself and others in the code. PHP supports single-line and multi-line comments:
Echo and Print Statements
The echo and print statements are used in PHP to output data to the screen. Both can be used interchangeably in most cases, but echo is slightly faster:
Semicolons
In PHP, semicolons (;
) are used to denote the end of a statement, similar to languages like C, Java, and JavaScript:
Variables
Variables in PHP start with a $
sign, followed by the name of the variable:
Case Sensitivity
In PHP, all keywords (like if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. However, all variable names are case-sensitive.
Last updated