教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 数组转换字符串php代码

数组转换字符串php代码

发布时间:2016-10-27   编辑:jiaochengji.com
教程集为您提供数组转换字符串php代码等资源,欢迎您收藏本站,我们将为您提供最新的数组转换字符串php代码资源
本文章是一个实例,功能是数组转换字符串php代码哦,他能把一维数组,二维数组都转换成字符串代码。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3961')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3961><?php
$fruits = array (
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
$arr1 = array(1, 2, 3, 4, 5, 6=>'fanglor');
function arr2str ($arr)
{
static $res_arr = array();
if (is_array ($arr))
{
foreach ($arr as $key => $val )
{
if (is_array($val))
{
arr2str ($val);
}
else
{
$res_arr[] = $val;
}
}
}
elseif (is_string ($arr))
{
$res_arr[] = $arr;
}
return implode(',',$res_arr);
}
$str = arr2str ($arr1);
print_r ($str);
?>

您可能感兴趣的文章:
PHP 数组字符集编码转换的函数
js字符串数组相互转换
php将数组转成字符串并保存到数据库
PHP字符串函数与使用分析
php获取字符串的编码格式的函数
js数组转化为字符串示例
php字符串函数有哪些
php5 字符串处理函数汇总
php二维数组转换为字符串示例
php字符串处理函数

上一篇:session 教程二 下一篇:session全教程(二)
[关闭]
~ ~