bsmbahamas
02-22-2007, 03:07 PM
is there a built in function here http://bs.php.net/manual/en/ref.array.php
that will allow me to count how many times a particular element occurs in an array?
i've created a unique array and i want to loop through each element of
the unique array and have it count how many times that particular element
occurs in the original array.
i tried
for( $i = 0; $i < sizeof($unique_array); $i++ ){
$temp_count = count($original_array,$unique_array[$i]);
echo "<li>$unique_array[$i]: $temp_count";
}
am i using count() incorrectly or does it not work this way?
the original array will change over time, so i first create a unique array,
and then loop throught the unique array one element at a time and count
how many times that particular element occured in the original array
and display it in a table. so if there are 12 different elements, but they
are repeated many times, it should produce a neat table with how many times
each of the 12 elements occurs.
array_count_values() works fine, but i don't know how to access the elements in the array it creates so i can have it print out in a table instead
of accross my webpage like print_r($my_array); does.
help please
that will allow me to count how many times a particular element occurs in an array?
i've created a unique array and i want to loop through each element of
the unique array and have it count how many times that particular element
occurs in the original array.
i tried
for( $i = 0; $i < sizeof($unique_array); $i++ ){
$temp_count = count($original_array,$unique_array[$i]);
echo "<li>$unique_array[$i]: $temp_count";
}
am i using count() incorrectly or does it not work this way?
the original array will change over time, so i first create a unique array,
and then loop throught the unique array one element at a time and count
how many times that particular element occured in the original array
and display it in a table. so if there are 12 different elements, but they
are repeated many times, it should produce a neat table with how many times
each of the 12 elements occurs.
array_count_values() works fine, but i don't know how to access the elements in the array it creates so i can have it print out in a table instead
of accross my webpage like print_r($my_array); does.
help please