Home > Article > Backend Development > What is the usage of php explode?
php explode is used to break up a string into an array. The syntax of the explode function is "explode(separator,string,limit)". Its parameter separator specifies where to split the string, and the parameter string indicates to split String.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
explode()
Function handle The string is broken into an array.
Note: The "separator" parameter cannot be an empty string.
Note: This function is binary safe.
Syntax
explode(separator,string,limit)
Parameters
separator required. Specifies where to split the string.
string Required. The string to split.
limit
Optional. Specifies the number of array elements to be returned.
Possible values:
Greater than 0 - Returns an array containing at most limit elements
Less than 0 - Returns an array containing all but the last -limit elements Array
0 - Returns an array containing one element
[Recommended learning: "PHP Video Tutorial"]
Example 1
Use the limit parameter to return some array elements:
<?php $str = 'one,two,three,four'; // 零 limit print_r(explode(',',$str,0)); // 正的 limit print_r(explode(',',$str,2)); // 负的 limit print_r(explode(',',$str,-1)); ?>
The above is the detailed content of What is the usage of php explode?. For more information, please follow other related articles on the PHP Chinese website!