0

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

3
Contributors
5
Replies
25
Views
2 Years
Discussion Span
Last Post by slowlearner2010
1

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.

0

Thanks DaveAmour,

just got some answers and its worked.

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

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.