Forum Moderators: coopster

Message Too Old, No Replies

Count the array results (add them together)

         

jake66

12:22 am on Aug 9, 2009 (gmt 0)

10+ Year Member



I have a script that pulls a list of ordered products from the database.

I am having a hard time figuring out how to 'merge' the results.

Example:

for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {

$str = $order->products[$i]['name'];
$str_Pattern = '/[^ ]*$/';
preg_match($str_Pattern, $str, $results);

echo '<tr><td>'.$results[0].'</td>';

$results[0] will say the following:
Widget
Widget
Widget
Cool Widget
Not-so-cool Widget

If $results[0] is the same, can I merge that and say:
3 Widget
Cool Widget
Not-so-cool Widget

Is this even possible?

idfer

4:20 am on Aug 9, 2009 (gmt 0)

10+ Year Member



Try array_count_values [php.net]