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
while($result = mysql_fetch_assoc($total))
{
$cst[] = $result['customer'];
$partnumber[] = $result['partnumber'];
$misc[] = $result['misc'];
if(array_key_exists($result['misc'], $misc_num)) {
$misc_num[$result['misc']] += 1;
} else {
$misc_num[$result['misc']] = 1;
}
}
I think that should do it!
Use array_count_values.
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
)