Comma seperated implode & modifying returned string.


Posted on 16th Feb 2014 07:03 pm by admin

I have a PHP post form that posts up to 4 variables. I need whatever variables are passed to be combined into one comma seperated string (eg variable1,variable2,variable3,variable4). This i can do with the code below.

Code: [Select]$combo = array($one, $two, $three, $four);
$list = implode(",", $combo);
Did you know?Explore Trending and Topic pages for more stories like this.

my problem is that the form fields are optional by design so that the user doesn't always post all 4 variables. Sometimes they will post 1, sometimes they will post all 4. So if a user only selects two fields and submits the form i will end up with a string looking like:
variable1,variable2,,
when what i really want is (note the removal of the trailing commas at the end of the string):
variable1,variable2

Can anyone point me towards a possible solution for this?
No comments posted yet

Your Answer:

Login to answer
297 Like 14 Dislike
Previous forums Next forums
Other forums

How can use this array as a key?
Say I have this array for example:


print_r($array);

Prints:
Code: [Select]Array

Limiting uploaded file type
Hi. First post here
I am working on a simple upload script, and I need it to limit the allowed f

php code generators
All

Whilst enjoying learning a new language i have come accross a number of free code generat

While Problem
i am having a problem with a while statement here is the code
Code: [Select]<?php
sess

mysql select with $_get ?
Hi, i have this code:
Code: // If char id is 0 and character dont exist do:
if ($_GET["id

noob question
i traying to do a php form with auto replay for both(me and the user who send me a mail),

a u

login box shows up again after logging in 2nd login works
Hello,

I am having trouble on my site Lockerz.rack111.com where when you login the login box

Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code,

Need Reporting Advice
My SQL server doesn't support MS SQL reporting services that comes with SQL Enterprise or Express. T

Comment Mod System Effects all rows...
Sorry if its confusing but here is whats going on: I have a table in a database called comments and

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash