猿问

如何实现laravel中的每个数据都有双引号(Implode)

嗨开发人员我有问题我不知道这是什么类型的内爆,我想要实现的是在每个数据中都有一个双引号。前任。"1600","1793","3211" 但是在我的输出中我看起来像 "1600,1608" 所以在我的 sql 中查询是错误的。那么是否可以让我的数据看起来像这样 "1600","1608" ?


我将向你们展示我的示例代码:


$selected_store = $request->get('selected_store');

$converted_selected_store = '"'.implode('","',(array)$selected_store).'"';


dd($converted_selected_store);

我的输出:

我的目标:

"1600","1608"


沧海一幻觉
浏览 2046回答 2
2回答

德玛西亚99

显然你$selected_store是一个简单的字符串,所以它就足够了 apply str_replace(),比如:$converted_selected_store = '"'.str_replace(',','","',$selected_store).'"';

手掌心

你也可以试试implode(array_map(function($x) { return '"' . $x . '"';}, $selected_store), ',');
随时随地看视频慕课网APP
我要回答