PHP connection function implode () and split explode ()

Source: Internet
Author: User

  

PHP can divide the string into an array, and also can be connected to the string, and the exact connection of the array elements into a string, with these two functions we can be between the array and the string of free conversion, see the example of the text below.

Implode () Join function:


This function implements connecting an array element to a string, before we give it two arguments, one is the connector that is going to be connected to the array


Note is a one-dimensional array oh, the multidimensional Small series is seldom used, but we can try.


Example:


<?php


$array = Array (' a ' = = 1, ' B ' =>2, ' C ' =>3, ' d ' =>4);


$string = Implode ("-", $array)


Echo $string;


The result is: 1-2-3-4;


?>


Explode () Split function:


This function is to divide the string into the array, we still give it two parameters, one is the delimiter is going to be split string


Note that this delimiter is present in the string, and we still use the above results as an example.


<?php


$string = "1-2-3-4";


$array = Explode ("-", $string);


echo "<pre>";


Print_r ($array);


= = = The result is an array of the above example definitions, and the small part here is not written.


?>

PHP connection function implode () and split explode ()

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.