Tan*_*uta 1 php arrays string replace
我有一个变量$input,其中包含一个数组,该数组具有可变数量的项目。
如何创建一个用逗号分隔的字符串,为每个值显示一个问号,并在每个问号周围加上引号,如下例所示?
我尝试使用以下内容,但这将所有问号都包装在一个引号中,而不是在每个问号周围都使用引号:
我的尝试:
$output = implode(",", array_fill(0, count($input), "?"));
Run Code Online (Sandbox Code Playgroud)
数组示例:
array(5) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
[3]=>
string(1) "4"
[4]=>
string(1) "5"
}
Run Code Online (Sandbox Code Playgroud)
预期产量:
$output = "?", "?", "?", "?", "?"
Run Code Online (Sandbox Code Playgroud)
电流输出:
$output = "?, ?, ?, ?, ?"
Run Code Online (Sandbox Code Playgroud)
尝试这个:
$output = implode( ", ", array_fill(0, count($input), "\"?\"" ));
Run Code Online (Sandbox Code Playgroud)