Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 8th, 2013  |  syntax: None  |  size: 2.77 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. if(in_array($browser, $uniqueBrowser)) {        
  2.     if(in_array($version, $uniqueBrowser[$browser])) {
  3.         $uniqueBrowser[$browser][$version]['times'] = $uniqueBrowser[$browser][$version]['times'] + 1;
  4.     } else {            
  5.         $uniqueBrowser[$browser]['version'] = $version;
  6.         $uniqueBrowser[$browser][$version]['times'] = 1;
  7.     }      
  8. } else {
  9.     $uniqueBrowser[] = $browser;
  10.     $uniqueBrowser[$browser]['version'] = $version;
  11.     $uniqueBrowser[$browser][$version]['times'] = 1;
  12. }
  13.        
  14. Browser data: array(4) {
  15.   [0]=>
  16.   string(7) "Firefox"
  17.   ["Firefox"]=>
  18.   array(3) {
  19.     ["version"]=>
  20.     string(6) "14.0.1"
  21.     [15]=>
  22.     array(1) {
  23.       ["times"]=>
  24.       int(2)
  25.     }
  26.     ["14.0.1"]=>
  27.     array(1) {
  28.       ["times"]=>
  29.       int(15)
  30.     }
  31.   }
  32.   [1]=>
  33.   string(17) "Internet Explorer"
  34.   ["Internet Explorer"]=>
  35.   array(2) {
  36.     ["version"]=>
  37.     string(9) "8.0.0.253"
  38.     ["8.0.0.253"]=>
  39.     array(1) {
  40.       ["times"]=>
  41.       int(1)
  42.     }
  43.   }
  44. }
  45.        
  46. +---------+------------------+------+-----+---------+----------------+
  47. | Field   | Type             | Null | Key | Default | Extra          |
  48. +---------+------------------+------+-----+---------+----------------+
  49. | id      | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
  50. | browser | varchar(120)     | YES  |     | NULL    |                |
  51. | version | varchar(50)      | YES  |     | NULL    |                |
  52. +---------+------------------+------+-----+---------+----------------+
  53.        
  54. +----+---------+---------+
  55. | id | browser | version |
  56. +----+---------+---------+
  57. |  1 | Firefox | 3.6     |
  58. |  2 | Firefox | 4.1     |
  59. |  3 | Firefox | 3.6     |
  60. |  4 | Safari  | 5.1.7   |
  61. |  5 | Safari  | 6       |
  62. |  6 | Firefox | 14.0.1  |
  63. |  7 | IE      | 7       |
  64. |  8 | IE      | 8       |
  65. |  9 | IE      | 7       |
  66. | 10 | Firefox | 14.0.1  |
  67. | 11 | Opera   | 12.0.1  |
  68. | 12 | Safari  | 5.1.7   |
  69. +----+---------+---------+
  70.        
  71. mysql> SELECT browser, version, COUNT(version) AS times FROM demo.browsers GROUP BY browser;
  72. +---------+---------+-------+
  73. | browser | version | times |
  74. +---------+---------+-------+
  75. | Firefox | 3.6     |     5 |
  76. | IE      | 7       |     3 |
  77. | Opera   | 12.0.1  |     1 |
  78. | Safari  | 5.1.7   |     3 |
  79. +---------+---------+-------+
  80.        
  81. mysql> SELECT browser, version, COUNT(version) AS times FROM demo.browsers GROUP BY browser, version;
  82. +---------+---------+-------+
  83. | browser | version | times |
  84. +---------+---------+-------+
  85. | Firefox | 14.0.1  |     2 |
  86. | Firefox | 3.6     |     2 |
  87. | Firefox | 4.1     |     1 |
  88. | IE      | 7       |     2 |
  89. | IE      | 8       |     1 |
  90. | Opera   | 12.0.1  |     1 |
  91. | Safari  | 5.1.7   |     2 |
  92. | Safari  | 6       |     1 |
  93. +---------+---------+-------+
  94.        
  95. foreach ($uniqueBrowser as $browserName=>$values){
  96.  
  97.     echo $browserName .' contains '. print_r($values,true);
  98.  
  99. }
clone this paste RAW Paste Data