编程语言
首页 > 编程语言> > PHP-为什么在以下情况下回声后没有插入换行符?

PHP-为什么在以下情况下回声后没有插入换行符?

作者:互联网

我下面的代码行:

$value['street1'] = "MCN";
$value['street2'] = "Bhavani peth spur";
$value['city'] = "Los Angeles";
$value['state_code'] = "CA";
$value['zip_code'] = 90009;



$temp_rebate_data['user_address'] = $value['street1']."".($value['street2'] ? "\n".$value['street2'] : '')."\n".$value['city']."".$value['state_code']."-".$value['zip_code'];

echo $temp_rebate_data['user_address'];

die;

上面的代码输出如下:

MCN Bhavani peth spur Los AngelesCA-90009

预期输出应如下:

MCN,
Bhavani peth spur,
Los Angeles, CA - 90009

有人可以帮我做错什么吗?

解决方法:

这应该为您工作:

$temp_rebate_data['user_address'] = $value['street1'].",".($value['street2'] ? "<br />".$value['street2'] . "," : '')."<br />".$value['city'].", ".$value['state_code']." - ".$value['zip_code'];

标签:line-breaks,string-concatenation,newline,string,php
来源: https://codeday.me/bug/20191121/2048694.html