Home | Login | Register | user control panel | view your posts |
question
FAQ
news
News
feedback
Feedback
HTML CSS PHP SQL
View unread posts | View new posts | View active posts
Login | Register | Search:
PHP array to comma separated string with quotes
user
forum by: user: nick, Post on: 2021-10-12 16:38:58, Posts: 129

php array to comma separated string with quotes

user: nick / Posts: 1 / post on: 2021-02-01 23:35:26
user
php array to comma separated string with quotes
Use ' before and after implode()

<?php
$my_arr = array("Hi","this","is","my","array");

$result = "'" . implode ( "', '", $my_arr ) . "'";

echo $result; // 'Hi', 'this', 'is', 'my', 'array'
?>

user: admin / Posts: 2 / post on: 2021-02-02 23:40:55
user
php array to comma separated string with quotes
Here is another way:
<?php
$my_arr = ['qwerty', 'QTPQ', 'FRQO'];
$my_str = implode(', ', array_map(function($val){return sprintf("'%s'", $val);}, $my_arr));
echo $my_str; //'qwerty', 'QTPQ', 'FRQO'
?>

sprintf() is a clean way of wrapping the single quotes around each item in the array
array_map() executes this for each array item and returns the updated array
implode() then turns the updated array with into a string using a comma as glue

user: Chrys / Posts: 3 / post on: 2021-02-03 23:40:55
user
php array to comma separated string with quotes
adding single qoutes to an arraylist having comma separated values

can any one please help me on this.

 (int i = 0; i < gridview1.Rows.Count; i++)
{
   string Emp2 = ((TextBox)gridview1.Rows[i].FindControl("TxtEmp")).Text;
   histList.Add(Emp2.ToString());
}
String EmpArrayCsv = String.Join("','", histList.ToArray());


Post User for this topic: title
Please Login to replay: Login | Register