/** * Retrieve all the tags from the BD and count the number of occurrences of each tag * @return Array with the tags and the number of times they were mentioned */ function sumAllTags() { $data = FacebookTags::all(); //Retrieve all data relative to tags $sumTags = array(); $tags = json_decode($data); foreach ($tags as $key => $value) { $tags = $value->Tags; foreach ($tags as $id => $tagValue) { if (isset($sumTags[$id])) { $sumTags[$id] += $tagValue; } else { $sumTags[$id] = $tagValue; } } } return $sumTags; }