PHP/Data Structure/array count values

Материал из Web эксперт
Перейти к: навигация, поиск

array_count_values demo

 
<?php
$states = array("Ohio","Iowa","Arizona","Iowa","Ohio");
$stateFrequency = array_count_values($states);
print_r($stateFrequency);
?>



array_count_values() function counts the frequency of the values.

 
Its syntax is: array array_count_values (array array);
<?
    $states = array("OH", "OK", "CA", "PA", "OH", "OH", "PA", "AK");
    $state_freq = array_count_values($states);
    print_r( $state_freq );
    
?>



Counts all the values of an array with array array_count_values (array input)

 
<?
$array = array(1, "hello", 1, "world", "hello");
array_count_values($array);
?>