Q:

How to create comma separated words

I have a Blog System Where I'm fetching category Name From Database. Here is what I've tried->
<li><span>Categories:</span>

<?php
   $a = mysqli_query($connecDB, "SELECT * FROM vector_cat WHERE post_id='$puser'");
   while( $b = mysqli_fetch_array($a) ){
?>
<a href="https://www.twekr.com/free-vectors/<?php echo $b['post_id']; ?>"><?php echo $b['cat_name']; ?></a>, &nbsp;
<?php } ?>

</li>

This Results in ->  Fashion, Technology, PHP, Mysql,
The problem I'm Facing is How can i remove the last comma from the result

A:

You can use rtrim().

This function returns a string with whitespace stripped from the end of str.

rtrim($string, ',');

Second parameter indicates the character to be deleted.

