Home > Backend Development > PHP Tutorial > PHP method to convert multi-dimensional array to string and multi-dimensional array to one-dimensional array_php skills

PHP method to convert multi-dimensional array to string and multi-dimensional array to one-dimensional array_php skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 20:08:37
Original
1071 people have browsed it

The examples in this article describe the methods of converting multi-dimensional arrays to strings and converting multi-dimensional arrays to one-dimensional arrays in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

/** 
* @method 多维数组转字符串 
* @param type $array 
* @return type $srting 
* @author yanhuixian 
*/ 
function arrayToString($arr) { 
if (is_array($arr)){ 
return implode(',', array_map('arrayToString', $arr)); 
} 
return $arr; 
} 
/** 
* @method 多维数组变成一维数组 
* @staticvar array $result_array 
* @param type $array 
* @return type $array 
* @author yanhuixian 
*/ 
function multi2array($array) { 
static $result_array = array(); 
foreach ($array as $key => $value) { 
if (is_array($value)) { 
array_multi2array($value); 
} 
else 
$result_array[$key] = $value; 
} 
return $result_array; 
}

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template