The implode () function of the PHP string is used

Source: Internet
Author: User

Implode
  • (PHP 4, PHP 5, PHP 7)
  • Implode-join array elements with a string
  • Implode-converts the value of a one-dimensional array to a string
Description
implode($glue,array$pieces)implode(array$pieces)//Join array elements with a glue string.//用 glue 将一维数组的值连接为一个字符串。

Note:

  • Implode () can, for historical reasons, accept the IT parameters in either order. For consistency with explode (), however, it may is less confusing to use the documented order of arguments.
  • For historical reasons, implode () can receive two parameter sequences, but explode () does not work. However, you can avoid confusion by order in the document.
Parametersglue
    • Defaults to an empty string.
    • The default is an empty string.
Pieces
    • The array of strings to implode.
    • The array you want to convert.
Return Values
    • Returns a string containing a string representation of all the array elements in the same order, with the glue string BETW Een each element.
    • Returns a string whose contents are the values of an array separated by glue.
Examples
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/2/17* Time: PM 10:52 */$array=Array( "' LastName ', ' email ', ' Phone ' );$comma _separated=implode( ",", $array );//' LastName ', ' email ', ' phone 'Echo $comma _separated.Php_eol;//empty string when using a empty array:Echo '-------------------------'.Php_eol;Print_r( implode( ' Hello ', Array() ) ); //String (0) ""Echo '-------------------------'.Php_eol;$id _nums=Array( 1, 6,  A,  -,  - );$id _nums=implode( ", ", $id _nums );$sqlquery="SELECT ' Name ', Email,phone from ' usertable ' where user_id in ($id _nums)";//select ' name ', Email,phone from ' usertable ' where user_id in (1, 6 ,.)Echo $sqlquery.Php_eol;$sqlquery=the Select$comma _separatedFrom ' usertable ' where user_id in ($id _nums)";//select ' lastname ', ' email ', ' phone ' from ' usertable ' where user_id in (1, 6 ,.)Echo $sqlquery.Php_eol;$ar=Array( "Hello", NULL, "World" );Echo implode( ',', $ar ).Php_eol; //Hello,,world$picnames=Array( "Pic1.jpg", "Pic2.jpg", "Pic3.jpg", "Pic4.jpg", "Pic5.jpg", "Pic6.jpg", "Pic7.jpg" );$allpics=implode( "|", Array_slice( $picnames, 0, 5 ) );//pic1.jpg|pic2.jpg|pic3.jpg|pic4.jpg|pic5.jpgEcho $allpics.Php_eol;$test=implode( [ "One", 2, 3, "Four", 5.67 ] );Echo $test.Php_eol;//one23four5.67/////////////////////////////////////////////////////////////////////////////////////classFoo {protected $title;         Public function __construct( $title ){$this->title =$title;} Public function __tostring(){return $this->title;}}$array=[    NewFoo( ' foo ' ),    NewFoo( ' Bar ' ),    NewFoo( ' Qux ' )];//foo; bar; QuxEcho implode( '; ', $array );
See
    • http://php.net/manual/en/function.implode.php
All rights reserved

The implode () function of the PHP string is used

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.