Php explode () array_diff () implode () three functions

Source: Internet
Author: User

$ Str = 'Array 1, array 2, array 3, array 4 ';
$ Array = explode (',', $ str); // Save the regular string to an array

The explode () function separates strings into arrays.

Syntax
Explode (separator, string, limit) parameter description
Separator is required. Specifies where to split the string.
String is required. The string to be split.
Limit is optional. Specifies the maximum number of returned array elements.


$ Array = array_diff ($ array, array ('Array 2'); // delete an array item with 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, returns the key and value that does not appear in the second array in the form of an array.

Syntax
Syntax
Array_diff (array1, array2, array3 ...)

Parameter
Parameter description
Description
Array1 required. the first array is the array that the others will be compared
Required parameter. Specify the first benchmark array for comparison
Array2 required. an array to be compared with the first array
Required parameter. Specify the second array to be compared with the first array
Array3 optional. an array to be compared with the first array
Optional. Specifies the third array compared to the first array


$ Str = implode (',', $ array); // Save the array as a regular string

The implode () function combines array elements into a string.

Syntax
Implode (separator, array) parameter description
Optional. Specifies the content to be placed between array elements. The default value is "" (null string ).
Array is required. Array to be combined as a string.

Description
Although the separator parameter is optional. However, we recommend that you use two parameters for backward compatibility.

Echo $ str;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.