
PHP offers different kinds of operators having distinctive functionalities. Operators enable us to perform arithmetic activities, string concatenation, compare values and to perform boolean operations, more...In this article, we will learn string operators given by PHP. Let's first learn the types of string operators in php. There are two string operators provided by PHP.
1.Concatenation Operator ("."):
This operator combines two string values and returns it as a new string.
2.Concatenating Assignment operator (".="):
立即学习“PHP免费学习笔记(深入)”;
This operation attaches the argument on the right side to the argument on the left side.
本文档主要讲述的是Ruby on Rails字符串处理;在Ruby中创建一个字符串有多种方式。可以有两种方式表示一个字符串:用一对单引号包围字符('str')或用一对双引号包围字符("str") 这两种形式的区别在于对于包围的字符串的处理,用双引号构造的字符串能处理更多的转移字符。 希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
Let's demonstrate the utility of the above operators by following examples.
Example:
Output :
Goodmorning
解释:
这里我们取了两个变量$a和$b作为字符串。然后我们使用连接运算符(.)将这些字符串连接成一个字符串。
例子:
= 0;$i--) {
$a .= $b[$i];
}
echo " $a";
?>输出:
Hello Folks Good morning
解释:
在这个例子中,我们使用连接赋值运算符(".=")将字符串值与数组值连接起来。$a表示一个字符串,而$b表示一个数组,我们使用for循环将字符串$a与数组$b的值连接起来。
注意:
连接运算符('.')与"+"和" -"运算符具有相似的优先级,可能会产生意外的结果。
例子:
输出:
5
解释:
上述代码将打印出“5”而不是“Result: 10”,因为首先创建了字符串“Result5”,然后将其与5相加,得到5。这是因为非空非数字字符串“Result5”将被转换为0,并与5相加得到5。要打印出“Result: 10”,请使用括号改变优先级:
输出:
Result:10










