Home > php教程 > php手册 > PHP实现多维数组转字符串和多维数组转一维数组的方法,多维维数

PHP实现多维数组转字符串和多维数组转一维数组的方法,多维维数

WBOY
Release: 2016-06-13 08:56:14
Original
759 people have browsed it

PHP实现多维数组转字符串和多维数组转一维数组的方法,多维维数

本文实例讲述了PHP实现多维数组转字符串和多维数组转一维数组的方法。分享给大家供大家参考。具体实现方法如下:

/** 
* @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

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template