我遵循以下代码:
$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
有人可以在我做错的地方帮助我吗?
答案 0 :(得分:3)
这应该适合你:
$temp_rebate_data['user_address'] = $value['street1'].",".($value['street2'] ? "<br />".$value['street2'] . "," : '')."<br />".$value['city'].", ".$value['state_code']." - ".$value['zip_code'];
答案 1 :(得分:0)
在echo语句
中尝试使用shift + enter键替换新行字符