数组合并问题

WBOY
Release: 2016-06-23 14:14:51
Original
908 people have browsed it

$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);
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template