Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_count_values()

Example

Count the occurrences of all values in an array:

<?php
$a=array(“A”,“Cat”,“Dog”,“A”,“Dog”);
print_r(array_count_values($a));
?>

Definition and Usage

The array_count_values() function counts the frequency of each value in an array.

Syntax

array_count_values(array)

Parameter Values

Parameter

Description

array

Required. Specifies the array for which to count the values.

Technical Details

Return Value:

Returns an associative array where the keys are the original array’s values and the values are their respective counts.

PHP Version:

4+