What are Comments, Constant Variable, String Interpolation, Arithmetic and Assignment Operators in PHP?

Comments in PHP

Comments are those human-readable texts that we should add to make our code more understandable for other programmes. It is ignored by PHP and doesn’t affect your code.

Comment are of Two types.
i. One or Single-line Comment.
ii. Multi-line Comment.

i. One or Single-line Comment:- Single line Comment is used to comment one line at a time or used in one line.

There are two types of Single line Comment:-

  1. Starts with //
    Ex- //this is home section.
  2. Starts with #
    Ex- # this is footer section.

ii. Multi-line Comment:- It is used to comment more than one line at a time or used in more than one line. It starts with /* and ends with */.

Ex – /* this is
a multi-line
Comment*/

String Interpolation

String Interpolation is a feature or a quick shortcut which allows popping the value of a variable into a double-quoted string.

Ex – {Without String Interpolation}

{With String Interpolation}

Constant Variable

It is a type of variable which can’t be modified. To create a constant variable define() function is used.

Syntax :- define(“constant_variable”,value,case-insensitive);

Ex – define(“pi”,3.1415,True); {Note:- If case-insensitive is not assigned then, its by default FALSE}

Rules of Constant Varible :-

  1. No need to start the constant varible with the $ sign.
  2. Name only starts with a letter and an underscore(_).
  3. Variable name can’t start with a number.
  4. Constants are automatically global and can be used in the entire script.

Arithmetic/Math Operators

Sample Program

Output

Maths Functions

There are predefined mathematical Functions available in PHP to do the mathematics calculations. See the below list:-

Assignment Operators

This operator is used to assign value to the variables. For Ex –

$price=39.12 , $ram=$shyam=10 , $name=sushant

In the above example, Assignment operator (=) is used to assign the value (36.58) to the variable ($price).

Combined Assignment Operator

Sample Program

Output

To know more about Assignment Operator Click here – Assignment Operators

Click Here For Next Part –  What are If, Nested if, if else and, Nested if else Statement in PHP?