Home > Backend Development > PHP Problem > What is the concatenation operator in php?

What is the concatenation operator in php?

醉折花枝作酒筹
Release: 2023-03-11 22:28:02
Original
3880 people have browsed it

In the previous article, we learned how to get the length of a string. If you need it, please read "How to know the length of a string in php". This time we will introduce to you the string operators of PHP. You can refer to them if you need them.

First we understand string variables. After understanding string variables, we can better introduce string operators.

String variables are used for values ​​that contain characters. After creating the string, we can operate on it. You can use the string directly in the function or store it in a variable.

There’s no way to understand it simply. Let’s look at an example.

<?php
$txt="世界盛大,欢迎回家!";
$offer="World grand, welcome home!";
echo $txt; 
echo "<br>";
echo $offer;
?>
Copy after login

The result of this example is

What is the concatenation operator in php?

#It should be noted that when assigning a text value to a variable, please remember to add # to the text value. ##Single quotes or Double quotes, just like the example above.

Now, let’s look at the string operators.

First let’s look at an example, just use the above example and just modify it.


<?php
$txt="世界盛大,欢迎回家!";
$offer="World grand, welcome home!";
echo $txt . $offer;
echo "<br>";
echo $txt; 
echo $offer;
?>
Copy after login
Let’s look at this result


What is the concatenation operator in php?

Looking at this result, these two sentences seem to be the same, and there is no difference. So what does it mean when we use operators? The naming is the same, so why do I need to remember one more operator?

Let's take a closer look at the code. The first one uses only one echo, which is one sentence; and the second one uses two "echo", which is two sentences. This is the difference between one sentence and two sentences.


Let’s look at the first one again. He uses “

.” between variables. In this way, the function of “.” is to separate the original two sentences. into a sentence?

Let’s take a look at this operator in detail.

"." is the concatenation operator, which is used to connect two string values. One space and multiple space strings are the same in PHP. The " " sign in PHP can only be used as an arithmetic operator and cannot be used as a string operator. So we can use "." when we need to concatenate string values. There is another operator, which we will introduce in the next article.

That’s all. If you want to know anything else, you can click here. → →

php video tutorial

The above is the detailed content of What is the concatenation operator in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template