String Operators in PHP

Notes:

PHP String Operators : ( Concatenation operators)

PHP has two string operators:
. (Concatenation operator)
- converts the LHS and RHS operands to the string format and
- forms a new string by combining them

.= (short hand concatenation assignment operator)
- converts the LHS and RHS operands to the string format and
- forms a new string by combining them and
- assigns the resultant string to left hand side variable

Note: it is recommended to add space before and after the string operators

Example Code:

echo "Manjunath" . "Chidre"; // "ManjunathChidre"
echo "<br/>";
echo "Manjunath " . "Chidre"; // "Manjunath Chidre";
echo "<br/>";
echo "Manjunath" . " Chidre"; // "Manjunath Chidre";
echo "<br/>";
echo "Manjunath" . " " . "Chidre"; // "Manjunath Chidre";
echo "<br/>";
echo "<br/>";

echo "Manjunath" . "Chidre"; // "ManjunathChidre"
echo "<br/>";
echo "Score: " . 2; // "Score: 2"
echo "<br/>";
echo 2 . "Score: "; // "2Score: "
echo "<br/>";
echo 2 . 2;
echo "<br/>";
echo "<br/>";
echo "Score: " . 2 + 2; // 0 + 2 = 2
echo "<br/>";
echo "Score: " . (2 + 2); // "Score: 4"
echo "<br/>";
echo 2 + 2 . "Score: "; // "4Score: "
echo "<br/>";
echo "<br/>";

$myName = "Manjunath";
echo $myName; // Manjunath
echo "<br/>";
$myName .= " Chidre"; // $myName = $myName . " Chidre";
echo $myName; // Manjunath Chidre
echo "<br/>";
$myName .= " Aurad"; // $myName = $myName . " Aurad";
echo $myName;
echo "<br/>";

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a