1. Basic knowledge
A. NOTES:
<? PHP // This is a single-line comment # This is also a single-line comment /* This is a multiline comment block that spans multiple lines of */?>
B. Case sensitive:
In PHP, all user-defined functions, classes, and keywords (such as if, else, Echo, and so on) are not case sensitive.
In PHP, however, all variables are case-sensitive.
C. Variables:
<? PHP $x=5; // Defining Variables $y=6; $z=$x+$y; Echo $z; // Output Variable ?>
PHP Variable rules:
- The variable starts with the $ sign, followed by the name of the variable
- Variable names must begin with a letter or underscore
- Variable names cannot start with a number
- Variable names can contain only alphanumeric characters and underscores (A-Z, 0-9, and _)
- Variable names are case sensitive ($y and $Y are two different variables)
Note: The PHP variable name is case-sensitive!
<?PHP$x= 5;//Global ScopefunctionmyTest () {$y= 10;//Local Scope Echo"Variable:</p> inside the <p> test function"; EchoThe variable x is:$x"; Echo"<br>"; EchoThe variable y is:$y";} MyTest ();Echo"Variable:</p> outside of the <p> test function";EchoThe variable x is:$x";Echo"<br>";EchoThe variable y is:$y";?>PHP Variable Scope
In PHP, variables can be declared anywhere in the script.
The scope of a variable refers to the part of the script that a variable can be referenced/used.
PHP has three different scope of variables:
- Local (partial)
- Global (globally)
- Static (statically)
PHP Basic Learning process