我有一个复选框,当选中字段时,字段将返回到html表.我似乎无法删除最后一个逗号.
$faultTypesStr = '';
if(!empty($faultTypeIds)){
foreach($faultTypeIds as $faultTypeId){
$faultTypeResult = FaultType::find()->where(['FaultTypeId' => $faultTypeId])->one();
$faultTypesStr = $faultTypesStr.$faultTypeResult->FaultTypeName.', ';
}}
Run Code Online (Sandbox Code Playgroud)
这是我在html表中的显示方式.SMTP
<tr>
<td class="fields"> <b>Type Of Fault</b></td>
<td>'.$faultTypesStr.'</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
这个答案侧重于您的问题标题,还有另外两个答案可以为您的确切问题提供更好的解决方案.你应该首先建立更好的输出,你不需要修剪.
简单!使用rtrim
$string=rtrim($string,',');
Run Code Online (Sandbox Code Playgroud)
例如,如果需要,您还可以为其添加更多字符以进行删除
$string=rtrim($string,',.AbCd123'); // Remove Those individual chars if found at the end
Run Code Online (Sandbox Code Playgroud)
如果你想为双方都这样做,请使用修剪
| 归档时间: |
|
| 查看次数: |
248 次 |
| 最近记录: |