将一维或多维的数组连接成一个字符串的php代码
代码如下:
/* * ――――――――――――――――- * @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, 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); ?>
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23