Php to merge the same elements in an array. php to merge array elements _ PHP Tutorial

Source: Internet
Author: User
Php merges the same elements in the array. php merges the array elements. Php combines the same elements in an array. This article describes how php merges the same elements in an array. Share it with you for your reference. The specific method is as follows: php merges the same elements in an array, and php merges the array elements.

This example describes how to merge the same elements in an array in php. Share it with you for your reference. The details are as follows:

We have introduced N methods for deleting repeated arrays. In this example, the same elements in the array are deleted and only one element is retained. The example code is as follows:

The code is as follows:

<? Php
// Delete the same element from the array and retain only one element.
Function formatArray ($ array)
{
Sort ($ array );
$ Tem = "";
$ Temarray = array ();
$ J = 0;
For ($ I = 0; $ I {
If ($ array [$ I]! = $ Tem)
{
$ Temarray [$ j] = $ array [$ I];
$ J ++;
}
$ Tem = $ array [$ I];
}
Return $ temarray;
}
// Test the call function
$ Array = array ('A', 'BB ', 'AA', 3,4, 5, 5, 5, 'BC ');
$ Arr = formatArray ($ array );
Print_r ($ arr );
?>

I hope this article will help you with php programming.

Examples in this article describes how php combines the same elements in an array. Share it with you for your reference. Details...

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.