Remember PHP functions every day, jquery functions and Linux commands (iii)

Source: Internet
Author: User

Introduction: After learning PHP and jquery, the memory of the function is not in place, resulting in a lot of functions do not remember, so in order to promote their own memory, spend a little time every day to write this blog.

Date: 2016-12-21 Location: Taiyuan Weather: Sleet

One. PHP functions

1.array_count_values the number of occurrences of all values in the statistics array

Description

Array Array_count_values ($input)

The Array_count_values () function returns an array that takes the value of the input array as the key name and the number of occurrences of the value in the input array as the key value.

Parameters:

An array of $input statistics

return value:

Returns an associative array that uses the value in the input array as the key name, the number of occurrences in the array as the value.

Error/exception: a warning error ( E_WARNING ) is thrown for each element inside an array that is not a string and an integer type.

$test =[          "One" =>11,  "=>11", "  =>33"  , "=>144"  , "=>55", "" "=>55, "=>77", "=>77", "=>99",  "      ;p rint_r" (Array_count_values ($test));

The result is:

Array (    [One] = 2    [] = 1    [144] = 1    [+] = 2 [all]    = 2    [in] + 1)

Related functions:

    • COUNT ()-Calculates the number of cells in an array or the number of attributes in an object
    • Array_unique ()-Removes duplicate values from the divisor group
    • Array_values ()-Returns all values in the array
    • Count_chars ()-Returns information about the characters used in the string

If it is a two-dimensional array such as:

$ar 1[] = Array ("Red", "green", "yellow", "blue"); $ar 1[] = Array ("green", "yellow", "brown", "Red", "white", "yellow"); $ar 1[] = Array ("Red", "green", "Brown", "Blue", "Black", "yellow");p Rint_r (Array_count_values ($arr 1));

The result is:


Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154

Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154

Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154
Array ()

So write one for the multidimensional array:

Remember PHP functions every day, jquery functions and Linux commands (iii)

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.