One - One Code All

Blog Content

PHP数组转字符串(属性加单(双)引号,逗号分隔)

PHP   2012-05-08 19:24:45

PHP数组转字符串(属性加单(双)引号,逗号分隔)。

#join
 $str = " ' " . join("','", array_values($data) ) . " ' ";  // 使用需要的符号拼接
 
#str_replace
 $str = " ' ".str_replace( ",","','", implode(',',$data));  //使用需要的符号替换
 
#array_map  函数式实现
$str = join( ', ',array_map(function( $v ){  return "'".$v."'";},$data) );  //使用函数拼接



上一篇:thinkphp volist循环数组的key名和自增序号
下一篇:php判断key是否存在的两种方法

The minute you think of giving up, think of the reason why you held on so long.