Hi,

This is my problem :

foreach ($_POST['a'] as $b)
echo $b;

$_POST['a'] from my previous page, multiple selection list box (i get this data from my lookup table which user can add data on lookup table).

The result from $b is 060100060200060300. Is there any function to split this number into variable and commas between those nums.
I want the result to be like this,

$c = 060100,060200,060300

The reason i want this because i want to put $c into my sql query. :)

p/s: sorry for my bad explanation and english..wish you guys can help me

Thanks

insteadof echo $b, append a$ to C$ with a comma each time you go through your foreach. You will need a little finesse to make sure you don't end up with a comma at the very end.

Thanks DaveAmour,

just got some answers and its worked.

$c = array();
foreach ($_POST['a'] as $b){
array_push($c, "$b");}
echo $b = implode(', ', $c);

Well done :)

Hi all,

@slowlearner2010

just for the log, it seems you don't need the array_push() neither the loop, use trim() to remove extra spaces and then use implode(), then you should be done:

$a = array_map('trim', $_POST['a']);
$b = implode(',', $a);

At least, looking at your example, this seems to work fine. Bye!

Thank for addi info cereal, that simplified my code btw... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.