Couting occurrences of each value in an array

前端 未结 3 725
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 03:56

I\'m trying to sort and splice an array, however I\'m finding it very confusing.

I have pulled my data from a mysql table:

$total = mysql_query(\"SEL         


        
3条回答
  •  春和景丽
    2021-01-17 04:47

    I am considering your following codes

    $total = mysql_query("SELECT * FROM orders");
    while($result = mysql_fetch_assoc($total))
    {
     $cst[] = $result['customer'];
     $partnumber[] = $result['partnumber'];
     $misc[] = $result['misc'];
    }
    $misc = array(
                  [0] => red,
                  [1] = >red,
                  [2] => blue,
                  [3] => blue,
                  [4] => blue,
                  [5] => green,
                  [6] =>red
                  )

    Now you can implement array_count_values() function here like

    print_r(array_count_values($misc))

    This results the following data

    Array
    (
    [red] => 3
    [blue] => 3
    [green] => 1
    )

提交回复
热议问题