Jump to content

[SOLVED] please help~ counting data in arrays


desadevil

Recommended Posts

Hi, I'm new!  ;)

 

 

Say I have an array, and I want to count how many times values appear, and how many types of values are there in the array, what should I do?

 

e.g.

 

$hello = array("4", "12", "12", "3", "3", "12", "3", "4", "4", "12", "3");

 

So in this array, there are 3 types of values, 4, 12, 3. What should I do to make the program know the number of types of values?

 

Thank you!!!  :-*

You want to use the function array_count_values()

 

<?php
$hello = array("4", "12", "12", "3", "3", "12", "3", "4", "4", "12", "3");
$x = array_count_values($hello);
echo '<pre>' . print_r($x,true) . '</pre>';
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.