How to make sure that the last element in the array does not display a comma, but a period is displayed?
while($arFields = $res->Fetch()){ echo $arFields["NAME"].", "; } How to make sure that the last element in the array does not display a comma, but a period is displayed?
while($arFields = $res->Fetch()){ echo $arFields["NAME"].", "; } If the array is removed into the script's RAM, you can proceed as follows
<?php $arr = array(); while($arFields = $res->Fetch()){ $arr[] = $arFields["NAME"]; } if(count($arr) > 0) { echo implode(", ", $arr)."."; } print a comma before the next one, and after all add a period:
$first = true; while($arFields = $res->Fetch()){ echo ($first ? '' : ', ') . $arFields["NAME"]; $first = false; } echo '.'; $string = ""; while($arFields = $res->Fetch()){ $string .= $arFields["NAME"].", "; } echo rtrim($string, ", ")."."; rtrim() , or the first name will suffer, which (suddenly?) begins with "," - SergiksSource: https://ru.stackoverflow.com/questions/545746/
All Articles