//二维数组转化为字符串,中间用,隔开
function arr_to_str($arr){
foreach ($arr as $v){
$v=join(",",$v); //可以用implode将一维数组转换为用逗号连接的字符串,join是别名
$temp[] = $v;
}
foreach($temp as $v){
$t.=$v.",";
}
$t=substr($t,0,-1); //利用字符串截取函数消除最后一个逗号
return $t;
}
substr应用
$str="1,2,3,4,5,6,";
$newstr=substr($str,0,strlen($str)-1);
echo $newstr;
系统自带的函数也可实现这样的效果,两种方法:
substr($str, 0, -1);
rtrim($str, ",")