Home > Backend Development > PHP Tutorial > Rewrite the function to convert PHP two-dimensional/three-dimensional array to string_PHP tutorial

Rewrite the function to convert PHP two-dimensional/three-dimensional array to string_PHP tutorial

WBOY
Release: 2016-07-21 16:12:42
Original
860 people have browsed it

Due to work needs, I rewrote such a function based on the example function given in the manual. The code is as follows:

Copy the code The code is as follows:

//Convert all values ​​in the multi-dimensional array into strings————》Supports up to three-dimensional arrays
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 );
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313628.htmlTechArticleDue to work needs, I rewrote such a function based on the example function given in the manual. The code is as follows: Copy the code as follows: //Convert all values ​​in the multi-dimensional array...
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