[SOLVED] How do I add a comma after every string(php)

Issue

This Content is from Stack Overflow. Question asked by Axolotl

So the code below gets a name from a db(which is a string) and it outputs with “” and a comma.Well it was suppose to, but for some reason it only adds the quotation marks and not the commas.I need it to add the commas too.Thank for you help.

   <?php
$sl = "SELECT _eName FROM vrt;";
$ret = mysqli_query($conn, $sl);
$resultck = mysqli_num_fields($ret);
if ($resultck > 0){
 while ($row = mysqli_fetch_assoc(($ret))){

  $b = $row['e_Name'];
  $temp = array($b,);


  $req = "'" . implode ( "' , '", $temp ) . "'";
  
 echo $req;
  
   
  

 }}
?>



Solution

implode joins array elements with a string. Your variable $temp contains only a single element, so there is nothing to join and the element itself is returned.


This Question was asked in StackOverflow by Axolotl and Answered by schmauch It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?