Home > Backend Development > PHP Tutorial > 请问怎么把数组转成带单引号的字符串

请问怎么把数组转成带单引号的字符串

WBOY
Release: 2016-06-20 12:42:16
Original
1381 people have browsed it

请问怎么把数组转成带单引号的字符串
比如:array("123","321","111")
我想转成  " '123','321','111' " 


回复讨论(解决方案)

$a = array("123","321","111");$s = "'" . join("','", $a) . "'";echo $s;
Copy after login
'123','321','111'

$arr = array("123","321","111");$str = "'" . implode("','", string) . "'";
Copy after login

或者这样也可以

$arr = array("123","321","111");foreach($arr as &$v) $v = "'$v'";echo implode(',', $arr);
Copy after login

还可以这样

$a = array(1,2,3,4);echo join(',', array_map(function($v) {return "'$v'";}, $a));
Copy after login
'1','2','3','4'

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