PHP Making a CSV (Comma Separarted Values) variable from the Multiple Select List in PHP

<?php
   $listvals=$_POST['x_Assigned_States'];
   $n=count($listvals);
   echo "User chose $n items from the list.<br>\n";
 //  for($i=0;$i<count($listvals);$i++){
      //echo "Item $i=".$listvals[$i]."<br>\n";}
    $csvofstates=implode(",", array_values($listvals));
     echo  $csvofstates;
?>

If it involves the string values then try this

<?php
  if ($_POST['x_Assigned_States']){ $listvals=$_POST['x_Assigned_States'];
   $n=count($listvals);
   echo "User chose $n items from the list.<br>\n";
   for($i=0;$i<count($listvals);$i++){
      //echo "Item $i=".$listvals[$i]."<br>\n";}
   $listvals[$i]="'".$listvals[$i]."'";}
    $csvofstates=implode(",", array_values($listvals));
    // echo  $csvofstates;
    }
?>

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s