Home > Article > Backend Development > php explode() array_diff() implode() three functions_PHP tutorial
$str = 'array1,array2,array3,array4';
$array = explode(',',$str); //Save regular string into array
The explode() function splits a string into an array.
Grammar
explode(separator,string,limit) parameter description
separator required. Specifies where to split the string.
string required. The string to split.
limit is optional. Specifies the maximum number of array elements returned.
$array = array_diff($array,array('array2')); //Delete the array item of the specified value
The array_diff() function compares two or more arrays. If the key or value in the first array does not appear in the second array, it will be returned in the form of an array. The key and value that appear.
syntax
Grammar
array_diff(array1,array2,array3...)
parameter
Parameter description
Description
array1 required. the first array is the array that the others will be compared with
Required parameters. Specify the first benchmark array to participate in comparison
array2 required. an array to be compared with the first array
Required parameters. Specifies the second array
to be compared to the first array
array3 optional. an array to be compared with the first array
Optional parameters. Specifies the third array
$str = implode(',',$array); //Save the array as a regular string
implode() function combines array elements into a string.
Grammar
implode(separator,array) parameter description
separator optional. Specifies what is placed between array elements. Default is "" (empty string).
array required. Arrays to be combined into strings.
Description
Although the separator parameter is optional. However, for backward compatibility, it is recommended that you use two parameters.
echo $str;