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);

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

array_count_values question?
ok i'm trying to create a top ten list from a database of listed favorite movies.

the followi

Passing PHP variables from one page to another
Hello-

I'm having trouble figuring out how to transport a variable from one php file to anoth

multiple recipients + dbuser mail recall
Hello,

I am building a php login script.

When the user registers the script will send

Quick fix: Conditional statement with an array
Hi, I'm getting the temperature value off of the Environment Canada website along with the icon file

php - xml what is the best way to do this.
IN essence I want to have a script calling the info from the database.. I have no problem thus far,

Losing 'page' data
I have this code that allows me to update my database. But after updating, I lose the $_GET['page']

Mass activity scheduling
Hi experts,

Im facing some problems to deal with mass activity jobs.
When I run some

Sum of Values in an Array
This is probably really simple... but it's been years since I've written anything, so bare with me!<

article site help remaining text
Hi all hope you will be fine
I am creating a article site in this site i want to put some text on

adding up might be solved tell us cheers.
i think i finally solved this anybody.

last time i was getting the wrong results.

Code

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