php example code : array_count_values function in php - count frequency of input as keys and values
array-count-values-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>php example code : array_count_values function in php - count frequency of input as keys and values</title>
</head>
<body>
<h3>php example code : array_count_values function in php - count frequency of input as keys and values</h3>
<?php
/*
---------------------------------------------------------------
let us make an array, with some keys for different frequencies
---------------------------------------------------------------
*/
$myArray = array('key1', 'key2', 'key3', 5, 'key1', 'key2', 'key3','key1',5,'key2', 'key3','key1', 'key2', 'key3');
$finalArray = array_count_values($myArray);
/*
------------------------------------------------------------------
this function makes an array using the values of the input array
as keys & their frequency as values.
------------------------------------------------------------------
*/
echo "<p style='background:#ddd; color:red;'>Output of final array using array_count_values function</p>";
echo "<pre>";
print_r($finalArray);
echo "</pre>";
echo "<pre>";
var_dump($finalArray);
echo "</pre>";
?>
</body>
</html>

No comments:
Post a Comment
leave your comments here..