PHP statistics arrays and unique arrays

Source: Internet
Author: User
Tags php and mysql

Statistical frequency of the occurrence of array elements

The Array_count_values () function returns an array containing the associated key/value pairs. In the form of Z

Array array_count_values (array array)

Each of these keys represents a value in Input_array, and the corresponding value indicates that the key appears in Input_array (as a value)

The frequency. Examples are as follows:

$states = Array ("Ohio", "Iowa", "Arizona", "Iowa", "Ohio");

$stateFrequency = Array_count_values ($states);

Print_r ($stateFrequency);

This will return:

Array ([Ohio] = 2 [Iowa] = 2 [Arizona] + 1)


Determining unique array elements

The Array_uniqueo function removes all duplicate values in the array and returns an array of unique values. The form is:

Array array_unique (array array)

Examples are as follows:

$states = Array ("Ohio", "Iowa", "Arizona", "Iowa Gate" Ohio ");

$uniqueStates = Array_unique ($states);

Print_r ($uniqueStates);

This will return:

Array ([0] = Ohio [1] = Iowa [2] = Arizona)





"To the fishing" detailed tutorial See "PHP and MySQL program design," The 92nd page, OK Bookstore (www.okpdf.com) to provide free ebook: Click to download


650) this.width=650; "src=" Http://www.okpdf.com/attachment/1407/thread/3_1_f0f2fd7ffe57c75.png "width=" 384 "height = "516" alt= "3_1_f0f2fd7ffe57c75.png"/>







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.