Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在两个回音之间插入空格_Php_Echo_Space - Fatal编程技术网

Php 在两个回音之间插入空格

Php 在两个回音之间插入空格,php,echo,space,Php,Echo,Space,如何在返回的文本中sample1和sample2之间添加空格?以下是我到目前为止的情况: if ($eventid!="") { echo $get_event['sample1'], $get_event['sample2']; } 它非常简单,只需echo变量之间的一个空格 <?php if($eventid!=""){echo $get_event['sample1'] , ' ', $get_event['sample2']; } 缩进总是使事情更干净、更容易: if

如何在返回的文本中
sample1
sample2
之间添加空格?以下是我到目前为止的情况:

if ($eventid!="") { 
   echo $get_event['sample1'], $get_event['sample2']; 
}

它非常简单,只需
echo
变量之间的一个空格

<?php if($eventid!=""){echo $get_event['sample1'] , ' ', $get_event['sample2']; }

缩进总是使事情更干净、更容易:

if (!empty($eventid)) {
    echo $get_event['sample1'] . ' ' . $get_event['sample2'];
}
在PHP上,需要使用点(.)连接字符串。。。正如您在字符串运算符文档中看到的:


如果($eventid!=”){echo$get_event['sample1],$get_event['sample2'];}在
'sample1
之后是否缺少一个引号?
echo
也接受多个参数,就像OP使用的那样。@alex我没说没有,这两种方法都有效。。因为他问起了连接,所以我说了点而不是多个echo参数,因为不能总是用commas@MelanyChang只需将字符串更改为
,'