How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
PHP Operator
About PHP operator: In php Operators are used to perform operations on variables and values. How to work variable and value with operator
Arithmetic Operators
Operator | Operator Name | Description |
---|---|---|
+ | Addition Operator | Adding two integer numbers |
– | Substruction Operator | Minus two integer numbers |
* | Multiplication Operator | Multiply integer numbers |
/ | Division Operator | Dividing two numbers and generate quotient |
% | Division Operator | Dividing two numbers and generate reminder |
Example –
<?php $num1 = 34; $num2 = 22; $add = $num1+$num2; $sub = $num1-$num2; $mul = $num1*$num2; $div = $num1/$num2; echo 'Addition is '.$add.'<br>'; echo 'Substruction is '.$sub.'<br>'; echo 'Multiplication is '.$mul.'<br>'; echo 'Division is '.$div.'<br>'; ?>
Comparison Operators
Operator | Operator Name | Description |
---|---|---|
== | Equal Operator | Checking equality of two value of variable |
=== | Equal Operator | Checking data value and data type of two variable |
!= | Not equal Operator | Checking data are not equal |
<> | Not Equal | Checking data are not equal |
> | Grater than Operator | Return Maximum value of two variable |
< | Less than Operator | Return Minimum value of two variable |
>= | Grater than and equal Operator | Return Maximum and equal value of two variable |
< | Less than and equal Operator | Return Minimum and equal value of two variable |
Example –
<?php //Equal (==) Operator example $num1 = 12; $num2 = 12; if($num1==$num2) echo '== operator two numbers are equal <br>'; //Equal (===) Operator example $num1 = (float) 12; $num2=12; if($num1===$num2) echo '=== operator is working <br>'; else echo '=== operator is not working <br>'; //Not Equal (!=) operator example. $num1 = 12; $num2 = 13; if($num1 != $num2) echo '!= operator is working <br>'; else echo '!= operator is not working <br>'; //Not Equal (<>) operator example. $num1 = 12; $num2 = 13; if($num1 != $num2) echo '<> operator is working <br>'; else echo '<> operator is not working <br>'; // Grater than ( > ) operator example $num1 = 12; $num2 = 13; if($num1 > $num2) //if we check equality of two number then we have to use if($num1 >= $num2) echo 'Grater than operator ( > ) is working <br>'; else echo 'Grater than operator ( < ) is not working <br>'; // Grater than ( > ) operator example $num1 = 12; $num2 = 13; if($num1 < $num2) //if we check equality of two number then we have to use if($num <= $num2) echo 'Grater than operator ( < ) is working <br>'; else echo 'Grater than operator ( > ) is not working <br>'; ?>
Increment and Decrements Operator
Operator | Operator Name | Description |
---|---|---|
++ | Increment | Increment Operator |
— | Decrements | Decrements Operator |
Example –
<?php $i=1; while($i<=10) { echo $i.'<br>'; $i++; // Increment operator increments value and print } ?>
<?php $i=10; while($i>0) { echo $i.'<br>'; $i--; // Decrements operator increments value and print } ?>
Logical Operator
Operator | Operator Name | Description |
---|---|---|
&& | And | If all conditions are true then return true |
|| | OR | If one condition is true then it does not check next conditions and return true |
and | And | If all conditions are true then return true |
or | OR | If one condition is true then it does not check next conditions and return true |
xor | XOR | If one condition is true and others are false then return true |
! | NOT | It checks not true |
Eample of && / and-
<?php $val1 = 12; $val2 = 15; if($val1==12 and $val2==15) // if($val1==12 && $val2==15) Both conditions are same echo 'true'; else echo 'false'; ?>
Example of || / or-
<?php //If Both conditions are true, then it will return true; $val1 = 12; $val2 = 15; if($val1==12 or $val2==10) // if($val1==12 || $val2==15) Both conditions are same echo 'true'; else echo 'false'; ?>
Eample xor-
<?php //If one condition is true, then it will return true otherwise return false; $val1 = 12; $val2 = 15; if($val1==12 xor $val2==15) // if($val1==12 || $val2==15) Both conditions are same echo 'true'; else echo 'false'; ?>
Example ! (not)-
<?php //making condition NOT $val1 = 12; if($val1!=10) echo 'true'; else echo 'false'; ?>
String Operator
Operator | Operator Name | Description |
---|---|---|
.(dot) | concatenation | Concatenate multiple string |
Example-
<?php $str1 = 'Hello '; $str2 = 'World!'; echo $str1.$str2; ?>
Related posts