views:

40

answers:

1

I'm using a loop to try to generate keyword combinations and also find the ones that have been used the most.

The loop finds all the records in the "posts" table where keyword = "chicago".

Within this loop, I need to generate strings. Which, would look something like "chicago bulls" "chicago bears" "chicago cubs" etc... How do I temporary hold these generated strings and count how many times they have been found within the loop?

+2  A: 

Teh pseudocode:

$usage = array();

foreach($posts as $post)
{
    foreach($post->keywords as $keyword)
    {
        if(!key_exists($keyword, $usage))
            $usage[$keyword] = 1;
        else
            $usage[$keyword]++;
    }
}

If solving the task in a hard way.

scaryzet
I think this is what I was looking for. I'm going to give it a try. Thanks!
mike
How would I sort this array by the most found string at the top?
mike
Use arsort(), than take the first element. You can read about array functions in php: http://www.php.net/manual/en/ref.array.php
scaryzet