Concatenate array values into strings-PHP source code

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.