Curriculum
In this tutorial, you’ll learn the fundamentals of PHP syntax, such as case sensitivity, statements, and whitespaces.
PHP, as a programming language, has a set of rules that govern how programmes are written.
To begin PHP code, you must use the opening tag, just as you would in HTML:
<?php
If you mix PHP code with HTML, you must use the following enclosing tag:
?>
For example,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP Syntax</title> </head> <body> <h1><?php echo 'PHP Syntax'; ?></h1> </body> </html>
However, if a file only contains PHP code, the enclosing tag is not required:
<?php echo 'PHP Syntax';
PHP is case-sensitive in some ways. Knowing what is case sensitive and what is not is critical for avoiding syntax errors.
You can use a function like COUNT if you have one. It would function properly.
In PHP, the following are case-insensitive:
A PHP script is usually made up of one or more statements. A statement is a piece of code that performs an action, such as assigning a value to a variable or calling a function.
A semicolon always follows the end of a statement (;). A statement that assigns a literal string to the $message variable is shown below:
$message = "Hello";
The example above is a straightforward statement. A compound statement in PHP is one that combines one or more simple statements. Curly braces are used to mark a block of code in a compound statement. Consider the following example:
if( $is_new_user ) { send_welcome_email(); }
The semicolon is not required after the curly brace ().
A semicolon is implied by the closing tag of a PHP block (?>). (;). As a result, a semicolon is not required in the last statement of a PHP block. Consider the following scenario:
<?php echo $name ?>
The statement echo $name does not require a semicolon in this case. Using a semicolon for the last sentence in a block, on the other hand, should function well. Consider the following scenario:
<?php echo $name; ?>
Whitespace and line breaks have no specific value in PHP in most circumstances. As a result, you can write a statement on a single line or across numerous lines.
The following code snippets, for example, are equivalent:
login( $username, $password );
and
login( $username, $password );