This article is an example. The function is to convert the php code of an array to a string. It can convert one-dimensional array and two-dimensional array to a string code. This article is an example. The function is to convert the php code of an array to a string. It can convert one-dimensional array and two-dimensional array to a string code.
Script ec (2); script
| The Code is as follows: |
|
$ 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 => 'hanglor ');
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 );
?> |