how to remove a duplicate word within a string , whereby this string is a value of an array ?
e.g
foreach($results as $result)
{
foreach($result as $words)
{
echo $words = str_word_count($words,0)."
";
}
}
result is e.g
test = 1
test activity = 2
test CI to CGI = 4
Test car Pool = 3
what i want to happen is, e.g remove the other duplicates of the word "test" and list all the unqiue word so that the result will only be
test = 1
activity = 1
CI = 1
to = 1
CGI = 1
car = 1
pool = 1
$final=array();
foreach($results as $result)
{
foreach($result as $key=> $words)
{
echo $words = str_word_count($words,0)."
";
if(!in_array($words,array_keys($final))
$final[$words]=str_word_count($words,0);
}
}
$results=array(
array(
"test",
"test activity",
"test CI to CGI",
"Test car Pool"
)
);
$ws=array();
foreach($results as $result)
{
foreach($result as $words)
{
$arr=explode(' ',$words);
foreach($arr as $word)
{
if($word!='')
{
if(!isset($ws[$word])) $ws[$word]=1;
else $ws[$word]++;
}
}
}
}
print_r($ws);