How to implode multiple values?
I have following implode method:
$a = array("".$_POST['questionid']."","$qid");
$b = array("".$_POST['AnswerID']."","$ans");
$c = array("".$_POST['timetaken']."","$time");
$comma = implode(",",$a);
echo "$comma";
it gives:1,2 and print a,b value
$comma = implode(",",$a);
echo "$comma";
$comma1 = implode(",",$b);
echo "$comma1";
it gives:1,34,2 how do i print 1,2,3,4
Why don't you add , by your self to variable $b
Change from
$comma1 = implode(",",$b);
into
$b[0] = ",".$b[0];
$comma1 = implode(",",$b);
echo $comma1;
2nd method: -
Secondly you can marge arrays by using array_merge() then you can implode it via ,
$comma = implode(",", array_merge($a, $b));
echo $comma;
You can use array_merge() to first merge all arrays and then implode them. Like this :
$comma = implode(",", array_merge($a, $b));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With