将一维或多维的数组连接成一个字符串的php代码

前端之家收集整理的这篇文章主要介绍了将一维或多维的数组连接成一个字符串的php代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="53718" class="copybut" id="copybut53718" onclick="doCopy('code53718')"> 代码如下:

<div class="codebody" id="code53718">
/
————————————————-
@file : 5.PHP
@function : arr2str
@copyright : 2002-2009 Xingmo Inc
@author : Fanglor <fanglor#163.com>
@date : 2010-06-25
@update :
————————————————-
/
<?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,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);
?>

原文链接:https://www.f2er.com/php/28375.html

猜你在找的PHP相关文章