php 内爆 (101) 带引号 [英] php implode (101) with quotes
本文介绍了php 内爆 (101) 带引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
内爆一个简单的数组
看起来像这样
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
那会返回这个
lastname,email,phone
太好了,所以我可能会这样做
great, so i might do this instead
$array = array('lastname', 'email', 'phone');
$comma_separated = implode("','", $array);
$comma_separated = "'".$comma_separated."'";
现在我有了我想要的漂亮漂亮的 csv 字符串
and now i have what I want a nice pretty csv string
'lastname','email','phone'
有没有更好的方法来做到这一点,我觉得应该有一个可选参数用于内爆我是否遗漏了什么?
is there a better way to do this, it feels to me like there should be an optional parameter for implode am I missing something ?
推荐答案
不,你这样做的方式很好.implode()
只需要 1-2 个参数(如果你只提供一个数组,它会用一个空字符串连接各个部分).
No, the way that you're doing it is just fine. implode()
only takes 1-2 parameters (if you just supply an array, it joins the pieces by an empty string).
这篇关于php 内爆 (101) 带引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文