PHP implements the method of converting multi-dimensional arrays to strings and multi-dimensional arrays to one-dimensional arrays. One-dimensional array method. Share it with everyone for your reference. The specific implementation method is as follows:
I hope this article will be helpful to everyone’s PHP programming design.
/**
* @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
http://www.bkjia.com/PHPjc/1044850.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1044850.htmlTechArticlePHP methods for converting multi-dimensional arrays to strings and converting multi-dimensional arrays to one-dimensional arrays. The examples of this article describe multi-dimensional arrays PHP implements methods of converting multi-dimensional arrays to strings and converting multi-dimensional arrays to one-dimensional arrays. ...