Concatenate array values into strings
Concatenate array values into strings
Concatenates all array values into a string.
The implode in php concatenates an array into a string. One disadvantage of this method is that the value of an array cannot be an array of basic types such as characters or numbers, if the value in the array is also an array, the conversion will fail. I have met this requirement in my actual project. I will share my code with you today. Hope to help you.
Please forgive me for your shortcomings.
$v ) { if( is_array( $v ) ) { $result .= $join. self::arrayConvertString( $v , $join ) ; } else { $result .= $join . $v ; } $result = preg_replace( "~^" . $join . "~" , "", $result ) ; } return $result ; }}// test$array = array( array(1,2,3,4,5),array("x1","x2","x3","x4","x5") ) ;$str = Convert::arrayConvertString( $array , ",") ;echo $str ;// echo:1,2,3,4,5,x1,x2,x3,x4,x5?>
The above is the content of concatenating array values into strings. For more information, see PHP Chinese network (www.php1.cn )!