NTRODUCTION
PHP is Hypertext preprocessor It is a server-side scripting language that is used for web development. It can be easily embedded with HTML files. HTML codes can also be written in a PHP file. The PHP codes are executed on the server-side whereas HTML codes are directly executed on the browser.
Characteristics:
- It is simple, easy and fast
- Flexible
- Open source
1. COMMENTS
- A comment in PHP code is a line that is not executed as a part of the program.
- It makes the code more readable
- our code will neat and clean
Types of Commond
- Single line comment ( // )
- Multiple lines comment( /* */ )
2. CONSTANTS
- constants are either identifiers or simple names that can be assigned any fixed values.
- Constant Identifiers should be written in upper case
- constant is always case-Sensitive
- It always starts with a letter or underscores, letter, numbers or underscore
- A constant name Must never start with a number
SYNTAX: define(name, value, case_insensitive)
3.ECHO / PRINT
- It has no return value and Print has return value of 1
- It can take multiple PArameters and Print can take only one parameter
- echo is faster than print
- example:
echo ” hi everyone “
echo ” hello world “
4.DATA TYPE
- String: string is a sequence of characters.
- Integer: it holds only whole numbers including positive and negative numbers, the default base is decimal (base 10).
- Boolean: It is used for conditional testing and hold only two values TRUE and FALSE.
- Array: It contain multiple values of same datatype in single variable
- Object: Objects are defined as instances of user-defined classes that can hold both values and functions and information. objects are explicitly declared and created from the new keyword.
- Null: These are special types of variables that can hold only one value NULL and it is case sensitive, If a variable is created without a value or no value, it is automatically assigned a value of NULL
5.SWITCH
- switch statement is used to execute one statement from multiple conditions
- Each case can have a break statement, which is used to terminate the sequence of statement.
- In switch statement, we can use number, character, string, functions
- Syntax
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}