如何在 PHP 中将两个字符串组合在一起? [英] How can I combine two strings together in PHP?
本文介绍了如何在 PHP 中将两个字符串组合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实际上不知道如何描述我想要的东西,但我会告诉你:
I don't actually know how to describe what I wanted, but I'll show you:
例如:
$data1 = "the color is";
$data2 = "red";
我应该怎么做(或处理)所以 $result 是 $data1
和 $data2
的组合?
What should I do (or process) so $result is the combination of $data1
and $data2
?
想要的结果:
$result = "the color is red";
推荐答案
$result = $data1 . $data2;
这称为字符串连接.不过,您的示例缺少空格,因此具体而言,您需要:
This is called string concatenation. Your example lacks a space though, so for that specifically, you would need:
$result = $data1 . ' ' . $data2;
这篇关于如何在 PHP 中将两个字符串组合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文