<pre name="code" class="php">//二维数组转化为字符串,中间用,隔开 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 application
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr;
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the conversion of two-dimensional arrays into strings in PHP, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.