PHP Operators Interview Questions & Answers

PHP Operators Interview Questions & Answers list

Here, you can read about PHP Operators related Interview Questions & Answers. With the help of this, you can learn more about various PHP operations. Find PHP Operators FAQs for Job Preparation.

How will you concatenate two strings in PHP?

To concatenate two string variables together, use the dot (.) operator.

What is the difference between == and === Operators in PHP?

PHP equal operator (==) and idential operator (===) are Relational or Comparison Operators in PHP langauge.

The only difference is that === operator matches the values along with Data types. While == operator only match values but not Data types.


Example to see difference between both operators

<?php
 
$num_1 = 12;
$num_2 = 12.00;
 
if ($num_1 == $num_2) {
    echo "Value matched using ==";
} else {
    echo "Value is not matched using ==";
}
 
echo "<br> Now we will check using === operator <br>";
 
if ($num_1 === $num_2) {
    echo "Value is matched using ===";
} else {
    echo "Value is not matched using ===";
}
 
?>

We have compared the two variable one by one by using == and === Operator, we get the following result.

Tutorials Class - Output Window

Value matched using ==
Now we will check using === operator
Value is not matched using ===

You will see that value is matched if used the equal operator '==‘ and not matched if used identical operator '===' because data type is not same for both numbers.

Therefore, if we need to match both values strictly with datatypes, '===' operator will be used else '==' will be used in PHP.