首頁 >後端開發 >php教程 >请问怎么把数组转成带单引号的字符串

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

WBOY
WBOY原創
2016-06-20 12:42:161381瀏覽

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


回复讨论(解决方案)

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

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

或者这样也可以

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

还可以这样

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn