如何在字符串中添加单引号


how to add single quotes in a string

我使用以下代码为字符串添加单引号

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

我的输出是这样的156’、155’、161’、151’、162’、163我想要这样的输出156、155、161、151、162、163请帮我

使用级联运算符

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

只需插入引号:

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

您有两个选项:

简单的一个:

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

第二个:

function add_quotes($str) {
    return sprintf("'%s'", $str);
}
$string =  implode(',', array_map('add_quotes', array_unique($groupIds)));

试试这个

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

这里$value将有单引号。