Home  >  Article  >  Backend Development  >  数组合并问题

数组合并问题

WBOY
WBOYOriginal
2016-06-23 14:14:51818browse

$act_arr = array(0=>'aaa',2=>'bbb');
我要变成下面的字符串
'aaa','bbb'
使用implode(',',$act_arr);
结果是aaa,bbb
怎么用快的方法,最好不要遍历,实现我要的效果。


回复讨论(解决方案)

要想得到单引号,应该要用转义字符吧!

echo "'".implode(',',$act_arr)."'";

这个才对
echo "'".implode("','",$act_arr)."'"; 

也来一个

$act_arr = array(0=>'aaa',2=>'bbb');$act_arr=array_map('foo',$act_arr);function foo($v){     return "'$v'";} echo implode(',',$act_arr);

$str="'".implode("','",$act_arr)."'";

明白了,就是把以逗号分隔(,),改为以','分隔就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn