CopyPastehas never been so tasty!

Negation and Not Equal Operator in PHP

by anonymous

  • 0
  • 0
  • 0
127 views

Orignal Source:http://codingvilla.com/negation-not-equal-operator-php-single-article-598.aspx

Negation Operator

 

Negation means opposite. Negation operator is used to make opposite of the $var. In bool data type two values are used turns and false. If bool data type variable have true value then with negation operator that turns into false.

 

For example

 

$a=true;

$b=!$a ;

So $b has opposite of $a that is false.

 

Code:

 

<?php

 

$a = 0;

 

$b=!$a;

 

echo "\$b value is $b" ;

echo "<br/>";

?>

 

 

Output:

 

$b value is 1

 

Explanation:

 

In the above code $a has ‘0 ‘value $b has its negation that is ‘1’.Negation operator opposite the identifier value.

 

Not Equal Operator

 

Not Equal operator checks if both values are equal or not.

 

Code:

 

 

<?php

$var1 = 34;

$var2 = 15;

echo "Current values of \$var1 is $var1 and \$var2 is $var2";

 

echo "<br/>";

if ($var1!= $var2) {

    echo "so not equal values";

} else {

    echo "equal values";

}

?>

 

 

Output:

 

Current values of $var1 is 34 and $var2 is 15

so not equal values

 

Explanation:

 

In the above code we have checked two variables $var1 and $var2 by not equal operator. If they are not equal then message will be displayed values are not equal. If they are equal means same values then they are equal message will be displayed.

Add A Comment: