A.C.Manikandan
A.C.Manikandan

Reputation: 227

how to add single quotes in a string

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

Answers (4)

venkat
venkat

Reputation: 11

Try this

$query=$key.'='."'$value'".',';

Here $value will have single quotes.

Upvotes: 1

Thamilhan
Thamilhan

Reputation: 13313

Using concatenation operator

$gpids = "'".implode("','",array_unique($groupIds))."'";

Upvotes: 7

Ajir
Ajir

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

Dhara Parmar
Dhara Parmar

Reputation: 8101

Just concate quote :

<?php
$gpids="'" . implode("','",array_unique($groupIds)) . "'";
echo $gpids;
?>

Upvotes: 4

Related Questions