1.explode Method Description
The Explode method allows a string to be split into groups by one string as a boundary point.
Array explode (string $delimiter, string $string [, int $limit]) 1
Returns an array of strings, each of which is a substring of string, separated by the delimiter as the boundary point.
parameter Description:
Delimiter
The delimited character on the boundary.
String
The input string
Limit
If the limit parameter is set and is a positive number, the returned array contains a maximum of 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 element are returned.
If limit is 0, it will be treated as 1.
2. Example
Use, split string
';p rint_r ($arr); Echo '
';? >1234567
Output:
Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5 [5] = 6 [6] = = 7
[7] = 8 [8] = 9) 123456789101112
Use, split string, limit is positive
';p rint_r ($arr); Echo '
';? >1234567
Output:
Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5,6,7,8,9) 12345678
Use, split string, negative limit
';p rint_r ($arr); Echo '
';? >1234567
Output:
Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5 [5] = 6) 123456789
Use, split string, limit is 0
';p rint_r ($arr); Echo '
';? >1234567
Output:
Array ( [0] = 1,2,3,4,5,6,7,8,9) 1234
3. Easy to ignore problems
In general, we use explode to split data such as ID strings.
$v) { //do sth }}?>123456789
Under normal circumstances, IDS is not empty, look at the code will not find any problem, because there is a judgment if (data), it is generally considered to have done an empty processing.
But the reality is ids=null, but data is not empty, causing problems with the code executing in foreach.
123456789
Because Ids=null, the array ([0] = =) instead of array () is derived using explode.
So the judgment needs to be modified to avoid problems.
$v) { //do sth }}?>