Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:15:09+00:00 2026-06-07T04:15:09+00:00

I am working on incorperating the jplayer html5 audio playlist I’m using a foreach

  • 0

I am working on incorperating the jplayer html5 audio playlist

I’m using a foreach to generate the script element for each playlist item.
Everything is working as expected, Except I’ve included the comma in the loop, but I need a way to write the comma as separator except for last item.

here is what I’ve got so far to generate jplayer playlist.

<?php foreach( $songs as $song ): if( !empty($song) ): ?>{

        title:"Each Song Title",

        mp3:"Each song mp3 url"

    },<?php endif; endforeach; ?>

which gives me

    {

        title:"Partir",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-09-Partir.mp3"

    },

    {

        title:"Thin Ice",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3"

    },
    {

        title:"Ice man",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3"

    },

This is my desired result

    {

        title:"Partir",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-09-Partir.mp3"

    },

    {

        title:"Thin Ice",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3"

    },
    {

        title:"Ice man",

        mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3"

    }

Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:15:11+00:00Added an answer on June 7, 2026 at 4:15 am

    I use next() for it:

    $arr = array(1,2,3,4,5,6,7);
    $copy = $arr;
    foreach ($arr as $val) {
        echo $val;
        if (next($copy )) {
            echo ','; // Add comma for all elements instead of last
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a small game using an HTML5 canvas, and javascript. And it's working
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
working on using a formula ive been using for a while to find distances
Working on an app using Akka 2 deployed with Play-mini. I pulled logback into
I'm working on implementing a high-performance server using IOCP & SocketAsyncEventArgs. From what I've
Working with an API that can handle multiple connections (i.e. sessions), each of these
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
Working on a new way of using an already existing searchengine in an application.
Working on a mobile application using jquery mobile and phonegap framework. My question is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.