Jump to content

merge array and count values


greg

Recommended Posts

I have the following array. Some values are in more than one group meaning that color belongs to more than one product.

array (size=6)
0 => string 'Beige' (length=5)
1 => string 'Blue' (length=4)
2 => string 'Green' (length=5)
3 => string 'Red' (length=3)
4 => string 'White' (length=5)
5 => string 'Yellow' (length=6)
array (size=6)
0 => string 'Black' (length=5)
1 => string 'Blue' (length=4)
2 => string 'Natural' (length=7)
3 => string 'Red' (length=3)
4 => string 'White' (length=5)
5 => string 'Yellow' (length=6)
array (size=12)
0 => string 'Black' (length=5)
1 => string 'Burgundy' (length=
2 => string 'Blue' (length=4)
3 => string 'Green' (length=5)
4 => string 'Gold' (length=4)
5 => string 'Orange' (length=6)
6 => string 'Purple' (length=6)
7 => string 'Red' (length=3)
8 => string 'Silver' (length=6)
9 => string 'Teal' (length=4)
10 => string 'White' (length=5)
11 => string 'Yellow' (length=6)

How can be merged in a way to get all values together and finally get these values counted so can get the result as seem at the end?

array (size=24)
  0 => string 'Beige' (length=5)
  1 => string 'Blue' (length=4)
  2 => string 'Green' (length=5)
  3 => string 'Red' (length=3)
  4 => string 'White' (length=5)
  5 => string 'Yellow' (length=6)
  6 => string 'Black' (length=5)
  7 => string 'Blue' (length=4)
  8 => string 'Natural' (length=7)
  9 => string 'Red' (length=3)
  10 => string 'White' (length=5)
  11 => string 'Yellow' (length=6)
  12 => string 'Black' (length=5)
  13 => string 'Burgundy' (length=
  14 => string 'Blue' (length=4)
  15 => string 'Green' (length=5)
  16 => string 'Gold' (length=4)
  17 => string 'Orange' (length=6)
  18 => string 'Purple' (length=6)
  19 => string 'Red' (length=3)
  20 => string 'Silver' (length=6)
  21 => string 'Teal' (length=4)
  22 => string 'White' (length=5)
  23 => string 'Yellow' (length=6)

Final Result

Beige (1)
Black (2)
Blue (3)
Burgundy (1)
Gold (1)
Green (2)
Natural (1)
Orange (1)
Purple (1)
Red (3)
Silver (1)
Teal (1)
White (3)
Yellow (3)

Greg

 

Link to comment
https://forums.phpfreaks.com/topic/295323-merge-array-and-count-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.