改写函数实现PHP二维/三维数组转字符串_php技巧

WBOY
Release: 2016-05-17 08:55:21
Original
835 people have browsed it

由于工作需要,自己在手册给定的示例函数基础上改写出了这样一个函数,代码如下:

复制代码 代码如下:

//将多维数组中所有的数值转换成字符串————》最多支持三维数组
function implodex( $glue, $array, $separator='' ) {
if ( ! is_array( $array ) ) return $array;
$string = array();

$count = 0;
foreach ( $array as $key => $val ) {
if ( is_array( $val ) )
$val = implode( $glue, $val );

if($count == 0){
$string[] = "{$val}";
}else{
$string[] = "{$glue}{$val}";
}
}

if(empty($separator))$separator = $glue;

return implode( $separator, $string );
}
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!