php convert string to array

Guanhui
Release: 2023-02-28 21:50:01
Original
4607 people have browsed it

php convert string to array

phpConvert a string to an array

In PHP, use the "explode function" to convert a string into an array. This function The usage is "explode(delimiter,string)", its parameter delimiter is represented as the delimiting character on the boundary, and the parameter string is represented as the input string.

explode description

explode ( string $delimiter , string $string [, int $limit ] ) : array
Copy after login

This function returns an array composed of strings. Each element is a substring of string. They are used as boundary points by string delimiter. Split it out.

explode parameters

delimiter:

The delimiter character on the boundary.

string:

The input string.

limit:

If the limit parameter is set and is a positive number, the returned array contains at most limit elements, and the last element will contain the remainder of the string.

If the limit parameter is a negative number, all elements except the last -limit elements are returned.

If limit is 0, it will be treated as 1.

Due to historical reasons, although implode() can receive two parameter orders, explode() cannot. You must ensure that the separator parameter comes before the string parameter.


Return value

This function returns an array composed of strings, each The elements are all substrings of string, and they are separated by string delimiter as boundary points.

If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value not found in string and a negative limit is used, an empty array is returned, otherwise an array containing a single element of string is returned.

The above is the detailed content of php convert string to array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template