Double not (!!) operator in PHP

PHPServer Side ProgrammingProgramming

In the Double not operator (!!), the first not i.e. ! is used to negate a value, whereas the second not i.e.! again negates. To implement Double not operator in PHP, the code is as follows−

Example

 Live Demo

<?php
   $str = "0.1";
   echo "Value = $str";
   $res = !!$str;
   echo "\nDouble Negated Value = $res";
?>

Output

This will produce the following output−

Value = 0.1
Double Negated Value = 1

Example

Let us now see another example −

 Live Demo

<?php
   $str = "100.56";
   echo "String = $str";
   $num = floatval($str);
   echo "\nNumber (Converted from String) = $num";
   $res = !!$num;
   echo "\nDouble Negated Value = $res";
?>

Output

This will produce the following output−

String = 100.56
Number (Converted from String) = 100.56 
Double Negated Value = 1
raja
Published on 26-Dec-2019 14:42:09
Advertisements