我想知道如何使我的implode()看起来像
name1, name2, name3,
这是我的代码
if (!empty($datas)) {
echo implode('<i class="fas fa-check-circle" style="color:green;font-size:20px;margin-bottom: 0px !important;float:right;" ></i><br> ', $datas);;
}
基本上我也想将分隔符添加到最后一项
答案 0 :(得分:0)
可以尝试
$output = join("seperator",implode(.....));
还是疯狂的想法。放大,然后手动将其添加到:
if (!empty($datas)) {
$imploded = implode('<i class="fas fa-check-circle" style="color:green;font-size:20px;margin-bottom: 0px !important;float:right;" ></i><br> ', $datas);
$imploded .= '<i class="fas fa-check-circle" style="color:green;font-size:20px;margin-bottom: 0px !important;float:right;" ></i><br>'
}
答案 1 :(得分:0)
以下三个示例可能会对您有所帮助。
$separator = '[separator]';
$d1 = ['Harry', 'Diana', 'Marvel'];
echo implode($separator, $d1) . "\n";
$d2 = ['Harry', 'Diana', 'Marvel', ''];
echo implode($separator, $d2) . "\n";
$d3 = ['', 'Harry', 'Diana', 'Marvel', ''];
echo implode($separator, $d3) . "\n";
这是输出
Harry[separator]Diana[separator]Marvel
Harry[separator]Diana[separator]Marvel[separator]
[separator]Harry[separator]Diana[separator]Marvel[separator]
答案 2 :(得分:0)
我会这样:
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
$comma_separated .= ',';