Reputation: 227
I am using the following code for adding the singles quotes for a string
$gpids=implode("','",array_unique($groupIds));
My output coming like these 156','155','161','151','162','163 I want my output like these '156','155','161','151','162','163' please help me
Upvotes: 1
Views: 12634
Reputation: 11
Try this
$query=$key.'='."'$value'".',';
Here $value will have single quotes.
Upvotes: 1
Reputation: 13313
Using concatenation operator
$gpids = "'".implode("','",array_unique($groupIds))."'";
Upvotes: 7
Reputation: 215
You have two options:
Simple one:
$string = "'" . implode("','",array_unique($groupIds)) . "'";
Second one:
function add_quotes($str) {
return sprintf("'%s'", $str);
}
$string = implode(',', array_map('add_quotes', array_unique($groupIds)));
Upvotes: 1
Reputation: 8101
Just concate quote :
<?php
$gpids="'" . implode("','",array_unique($groupIds)) . "'";
echo $gpids;
?>
Upvotes: 4