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

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

WBOY
Release: 2016-06-06 19:48:33
Original
1059 people have browsed it

这篇文章主要介绍了PHP实现多维数组转字符串和多维数组转一维数组的方法,以实例形式分别介绍了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; }

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

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