Deep analysis of implode and segmentation explode of PHP connection function

Source: Internet
Author: User
Tags explode learn php split

At present, there are many people who learn PHP, many of the friends who do PHP training always ask such a question: What is the PHP connection function implode?
PHP can split the string into a group, but also can be connected to the array of strings, the exact point is that the array elements can be connected to a string, with these two functions we can in the array and the string between the free conversion, see the text below the example bar.

Implode () connection function:
This function implementation connects an array element to a string, and before connecting we give it two arguments, one is a connector and one is the array to be connected
Note that the one-dimensional array oh, small-dimensional series is rarely used, but we can try.
Example:

Copy Code code as follows:
<?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 split the string into the array, we still give it two arguments, one is the delimiter, the other is the string that will be split.
Note that this delimiter is present in the string oh, we still use the results above as an example

Copy Code code as follows:


<?php
$string = "1-2-3-4";
$array = Explode ("-", $string);
echo "<pre>";
Print_r ($array);
= = = = = The result is an array of the examples above, where the small weave is not written.
?>

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.