Home > php教程 > php手册 > 改写函数实现PHP二维/三维数组转字符串

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

WBOY
Release: 2016-06-06 20:27:39
Original
1873 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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template