Home > Backend Development > PHP Tutorial > 改写函数实现PHP二维/三维数组转字符串_PHP

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

WBOY
Release: 2016-06-01 12:03:53
Original
988 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