PHP字符串串联使用“,"吗? [英] PHP string concatenation using ","?

查看:76
本文介绍了PHP字符串串联使用“,"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现了一些东西.

I just discovered something.

echo $var1 , " and " , $var2;

与以下相同:

echo $var1 . " and " . $var2;

php中实际的字符串连接运算符是什么?我应该使用.还是,?

What is the actual string concatenation operator in php? Should I be using . or ,?

推荐答案

.运算符是串联运算符.您的第一个示例之所以有效,是因为echo'function'(从技术上讲,这是一种语言构造,但不允许头发散开)接受多个参数,并将打印每个参数.

The . operator is the concatenation operator. Your first example only works because the echo 'function' (technically it's a language construct, but lets not split hairs) accepts more than one parameter, and will print each one.

因此,您的第一个示例正在调用带有多个参数的echo,并且都将其打印出来,而第二个示例中所有的字符串都已合并并且正在打印一个大字符串.

So your first example is calling echo with more than one parameter, and they are all being printed, vs. the second example where all the strings are being concatentated and that one big string is being printed.

这篇关于PHP字符串串联使用“,"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆