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 6087811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:54:46+00:00 2026-05-23T11:54:46+00:00

I have an array that loops through music tracks but I need to remove

  • 0

I have an array that loops through music tracks but I need to remove the comma from the last element of the array, can someone help?

<?php foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = "http://".$isdHtml5Bucket.".s3.amazonaws.com/".urlencode($fname);

if(preg_match("/\.mp3$/i", $furl)) { ?>
    {
            name:"<?php echo basename($fname); ?>",
            mp3:"<?php echo $furl; ?>"

        },
<?php }else{ ?>
        {
            name:"<?php echo basename($fname); ?>",
            m4a:"<?php echo $furl; ?>"

        },<?php } } ?>

And here is the output of the array.

    {
        name:"bassline",
        m4a:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fbassline%2F"

    },
    {
        name:"Project Bassline - Drop The Pressure (Jack Beats Rinsed Out Remix).mp3",
        mp3:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fbassline%2FProject+Bassline+-+Drop+The+Pressure+%28Jack+Beats+Rinsed+Out+Remix%29.mp3"

    },
        {
        name:"deadmau5 vs jelo   the reward is cheese.mp3",
        mp3:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fdeadmau5+vs+jelo+++the+reward+is+cheese.mp3"

    },
    {
        name:"vocal",
        m4a:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fvocal%2F"

    },      
            {
        name:"Thin Ice",
        free:true,
        mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3",
        oga:"http://www.jplayer.org/audio/ogg/Miaow-10-Thin-ice.ogg"
    },

If you scroll to the last element of the array you can see a comma is output.
I really need to remove this comma from the last element of the array.

Thanks

  • 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-05-23T11:54:47+00:00Added an answer on May 23, 2026 at 11:54 am

    pass your string through rtrim() and specify the comma in the charlist as a removable character:

    $str = rtrim($str, ',');
    

    Edit

    Or… perhaps this approach (not tested):

    $songs = array();
    
    foreach ($bucket_contents as $file) { 
    
        $fname = $file['name'];
        $furl  = "http://".$isdHtml5Bucket.".s3.amazonaws.com/".urlencode($fname);
    
        $type = preg_match("/\.mp3$/i", $furl) ? 'mp3' : 'm4a'; 
        $songs[] = sprintf('{ name: %s, %s: %s }', $fname, $type, $furi); 
    }
    
    echo implode(',', $songs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this code that loops through an array of lat/long coordinates and
I have code already that loops through each member of my website and can
I have a JUnit 4 test that loops through an array of test data:
I have script that loops through an array of html tag id's, some elements
I have a for loop that loops over one array... for i=1:length(myArray) In this
I have an array that stores a few urls of XML files that need
I have a foreach loop which loops through an array (simpleXML nodes). This array
I have a for loop which loops through an array and want to match
I have a function that gets some notifications, loops through them and the adds
I have some image processing code that loops through 2 multi-dimensional byte arrays (of

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.