使用 PHP 将 post 数组转换为单引号


convert post array to single quote using php

>我在数组中有这个表单帖子:

array([tags] => test,test1,test2,test3,test4);

我需要用单引号'和分隔来打印每个标签,如下所示,

'test','test1','test2','test3','test4'

如何创建和打印此输出?!

$tags = explode(',', $array['tags']);
$quoted_tags = array_map(function($x) { return "'$x'"; }, $tags);
$string = implode(',', $quoted_tags);

如果您要将其存储在数据库中,请不要忘记转义标签。

$tags = explode(',', $array['tags']);
echo implode(',', array_map(function($tag) { return "'$tag'"; }, $tags));
$newtags="'".str_replace(",","','",$array['tags'])."'";