Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
URL中是否需要PHP连接运算符空间?_Php - Fatal编程技术网

URL中是否需要PHP连接运算符空间?

URL中是否需要PHP连接运算符空间?,php,Php,我注意到,大多数使用串联运算符的示例都在“前后显示空白 例如: header('Location: http://google.com?c1=' . $var1 . '&c2=' . $var3); 但在本例中,如果没有空格,这似乎可以正常工作: header('Location: http://google.com?c1='.$var1.'&c2='.$var3); 第二种方式使用连接运算符是否有任何问题?否,添加空格是为了提高可读性 就像 if($var=='test')

我注意到,大多数使用串联运算符的示例都在“前后显示空白

例如:

header('Location: http://google.com?c1=' . $var1 . '&c2=' . $var3);
但在本例中,如果没有空格,这似乎可以正常工作:

header('Location: http://google.com?c1='.$var1.'&c2='.$var3);

第二种方式使用连接运算符是否有任何问题?

否,添加空格是为了提高可读性

就像

if($var=='test'){echo'ok';}


不需要空格,但它们使阅读更容易


这只是一个惯例问题,只是为了可读性。更具可读性的方法是省去连接并使用双引号:
header(“位置:http://google.com?c1=$var1&c2=$var3“给定一个具有合理语法突出显示的IDE
http\u build\u query()
if ($var == 'test') 
{
    echo  'ok';
}