Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

PHP Constant, Variable, Data Type Operator Tutorial with example

PHP Constant, Variable, Data Type Operator Tutorial with example

In this tutorial I am going to explain PHP Constant, Variable, Data Type Operator with simple examples.

Constant, Variable, Data Type Operator:

Constant: Constant refers to fixed value that does not change the value during the execution of program. Constant are defined using PHP’s define () function which accept two arguments. The $ prefixed is not required for constant.
Here is example of defining and using constant-
//define constant
//use constant
echo “Area of circle=”.$area;
Output: 78.5

Variable: Variable is a container that is use to store numeric and non numeric value for further use. Every variable name must prefix with dollar ($) symbol and must begin with a letter or underscore character. A variable name can be chosen by the programmer in the meaningful way like – $name, $student_address.
echo “Name=”.$name;

Data Type: For storing value in a variable it is not recommended to data type must be explicitly defined by programmer like other programming language as C,C++,Java.C# etc. during script variable change the value automatically which illustrate in following program. according to this nature php is called loosely type language.

echo “Value of num=”.$num;
echo “<br>”.”Data type of num=”.gettype($num).”<br>”;
echo”<br>”.”Now value of num=”.$num;
echo “<br>”.”Now data type of num=”.gettype($num);

Operator: An operator operates on variables and performs an action in a program. They usually form a part of the arithmetical or logical expression.
PHP operators can be classified into a number of categories . They are

  1. Arithmetical operator      :   +    ,  –  , *  , /   , %
  2. Relational operator          :   <  , <=  , > , >=  , =  =   ,= = =  , !=
  3. Logical operator                :   &&  (AND) ,  || (OR),   !  (NOT)
  4. Assignment operator       :  =
  5. Increment and Decrement operator: ++,  —
  6. Conditional operator        :  ? (ternary)
  7. Special operator                 :  -> ,  .(dot), $this ,   :: (scope resolution)

Now you will use each operator one by using example in next section.

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments