How to remove excess zapadnuju?

See, there's code comma-separated lists of values 2 what to do if only 1 value, the decimal point still?
<?php
 $count = 0;
 foreach (get_the_category() as $category) {
 if ($category--->term_id > 102) {
?>

 <a href="<?php echo get_term_link($category); ?>" class="link-ids<?php if ($category->term_id == $term_id) {
 echo "active"; } ?>"><?php echo $category--->cat_name;

 if ($count == 0 ) {
 echo ', ';
}
 else {
 echo ";
}
?></a>
<?php
$count++;
}
 }; ?>
July 5th 19 at 00:02
2 answers
July 5th 19 at 00:04
Solution
put the comma before, rather than after value. Of course it is necessary to check first whether this value, then a comma is not put.
July 5th 19 at 00:06
$cat = get_the_category();
$size = sizeof($cat);

if($count == $size){
 echo ";
} else {
 echo ', ';
}


Still, as an option, you can collect arrays of links and make a string using implode:

$arr = [
 '<a href>link 1 </a>',
 '<a href>link 1 </a>'
];

echo implode(',', $arr);
Did not help - Thurman54 commented on July 5th 19 at 00:09
not help because you have initially $count = 0, do $count = 1 - Etha_Bruen commented on July 5th 19 at 00:12

Find more questions by tags PHP