PHP code to concatenate one-dimensional or multi-dimensional arrays into a string_PHP tutorial

WBOY
Release: 2016-07-21 15:35:11
Original
1186 people have browsed it

复制代码 代码如下:

/*
* ————————————————-
* @file : 5.php
* @function : arr2str
* @copyright : 2002-2009 Xingmo Inc
* @author : Fanglor
* @date : 2010-06-25
* @update :
* ————————————————-
*/
$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);
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322304.htmlTechArticle复制代码 代码如下: /* * ————————————————- * @file : 5.php * @function : arr2str * @copyright : 2002-2009 Xingmo Inc * @author : Fanglor fang...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template