PHP implements the method of converting multi-dimensional arrays to strings and multi-dimensional arrays to one-dimensional arrays. One-dimensional array method. Share it with everyone for your reference. The specific implementation method is as follows:
I hope this article will be helpful to everyone’s PHP programming design.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | function arrayToString( $arr ) {
if ( is_array ( $arr )){
return implode( ',' , array_map ( 'arrayToString' , $arr ));
}
return $arr ;
}
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 ;
}
|
Copy after login
http://www.bkjia.com/PHPjc/1044850.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1044850.htmlTechArticlePHP methods for converting multi-dimensional arrays to strings and converting multi-dimensional arrays to one-dimensional arrays. The examples of this article describe multi-dimensional arrays PHP implements methods of converting multi-dimensional arrays to strings and converting multi-dimensional arrays to one-dimensional arrays. ...