Conversion of strings and arrays in php learning

Source: Internet
Author: User
In php learning, strings and arrays are two very important knowledge. Conversion between strings and arrays is frequently used in development. It is mainly implemented through The explode () function and implode () function.

In php learning, strings and arrays are two very important knowledge. Conversion between strings and arrays is frequently used in development. It is mainly implemented through The explode () function and implode () function.
1. convert the string into an array.
Explode (string separator, string, [int limit]) returns an array converted from a string. each element is a substring of a string, which is separated by the string separator.
If the limit parameter is set, the returned array contains up to limit elements, and the last few elements will contain the rest of the string.
If the separator is a null string "", The explode function returns false. if the value contained in the separator cannot be found in the string, The explode function returns an array of a single string element; if the limit value is negative, all elements except the last-limit element are returned.
For example:
$ Str = "messi, henry, xavi ";
$ Array = explode (",", $ str );
Var_dump ($ array );
2. convert an array to a string
Implode (string glue, array pieces)
The glue parameter is a string type and a delimiter. the pieces parameter is an array type to be converted.
For example:
$ Array = array ("team" => "barcelona", "name" => "messi ");
$ Str = implode (",", $ array );

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.