我有一个变量$input
,它包含一个项目数量可变的数组。
如何创建一个逗号分隔的字符串,显示每个值的问号和每个问号周围的引号,如下面的例子所示?
我试着使用下面的代码,但是它将所有的问号包装在一个引号中,而不是在每个问号周围使用引号:
我的尝试:
$output = implode(",", array_fill(0, count($input), "?"));
示例数组:
array(5) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
[3]=>
string(1) "4"
[4]=>
string(1) "5"
}
预期输出:
$output = "?", "?", "?", "?", "?"
当前输出:$output = "?, ?, ?, ?, ?"
试试这个:
$output = implode( ", ", array_fill(0, count($input), "'"?'"" ));
你可以这样做。
https://eval.in/401410<?php
$K= array("1","2","3","4","5");
$P=preg_filter('/^(.*)/', '"?"', $K);
echo implode(",",$P);
?>