Jump to content

Output items separated by comma apart from last item


Peter Knight
 Share

Recommended Posts

Hi

I have a page reference field which are a series of checkboxes in the back end

  • Web Design
  • Web Development
  • Marketing
  • Administration

In my template I was previously listing only 1 key skill at a time but now I need to output each checked item separated by a comma

IE

Marketing, Administration

This does work but echoes 

Marketing, Administration,

 foreach
                        ($staff->skills as $item){
                        echo "{$item->title},";}

How would I keep the comma from appearing at the end of the last item?

Thanks

Link to comment
Share on other sites

@kongondo's approach is definitely the best for PW, but just for extra info in case you ever need to do this with a standard PHP array, you can simply do:

image.png.0894a9070f8aaf16923f3c45ce2ff8cf.png

The ugly way is rarely useful, but I suppose there might be more flexibility depending on your needs.

 

  • Like 2
  • Haha 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...