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
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!