Welcome to WebmasterWorld Guest from 54.82.99.169

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Count the array results (add them together)

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

Preferred Member

10+ Year Member

joined:Nov 2, 2005
posts:505
votes: 0


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?

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

Junior Member

10+ Year Member

joined:Feb 13, 2008
posts:130
votes: 0


Try array_count_values [php.net]