本文章是一个实例,功能是数组转换字符串php代码,他能把一维数组,二维数组都转换成字符串代码,代码如下:
- <?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);
- } //开源代码Vevb.com
- $str = arr2str ($arr1);
- print_r ($str);
- ?>
新闻热点
疑难解答