Google News
logo
PHP Program to String Operators
In the following example of PHP program that demonstrates the use of string operators :
Program :
<?php

// Declare two strings
$str1 = "Hello";
$str2 = "World";

// Concatenation operator
$str3 = $str1 . " " . $str2;
echo "Concatenation operator: $str3 <br>";

// Concatenation assignment operator
$str1 .= $str2;
echo "Concatenation assignment operator: $str1 <br>";

// Equality operator
if ($str1 == $str2) {
    echo "Strings are equal <br>";
} else {
    echo "Strings are not equal <br>";
}

// Inequality operator
if ($str1 != $str2) {
    echo "Strings are not equal <br>";
} else {
    echo "Strings are equal <br>";
}

?>
Output :
Concatenation operator: Hello World
Concatenation assignment operator: HelloWorld
Strings are not equal
Strings are not equal
In this example, we have declared two strings `$str1` and `$str2` and assigned them the values `"Hello"` and `"World"`, respectively.

We then use string operators to concatenate the strings and compare them using equality and inequality operators.

Finally, we print out the results using the `echo` statement.