f I have the following array:
$myArray(jim,ed,gary,jim,jim,fred,gary,alice,mary, alice,alice);

What's a simple way to get a total on each unique value, such as:

jim=3
ed=1
gary=2
alice=3
mary=1
fred=1

thanks

    Thanks,
    This is what I ended up with;

    <?php
    $allFiles_array= array("wat","oil","oil","wat","oil","wat","wat","wat","pas","pas","pas","pas");
    $noDupes_array=array_unique($allFiles_array);
    $counted_array= array_count_values($allFiles_array);
    $lenNoDupes=count($noDupes_array);
    for ($i=0;$i<=8;$i++) {

    if ($noDupes_array[$i]!=""){
    print $noDupes_array[$i].$counted_array[$noDupes_array[$i]].",";
    }
    }
    // result
    //wat5,oil3,pas4,
    ?>

      You don't need the $noDupes_array.

      foreach($counted_array as $name=>$count)
      {
       echo $name,$count,',';
      }
      

        Remember to mark this thread as resolved (if it is) using the thread tools.

          Write a Reply...