これは簡単な質問です。
次のような単語のリストがあります。
word
word
one
two
three
four
five
.
....X100
word
word
単語 (1、2、3、4、5) を同じ順序で正確に 100 回繰り返します。単語 (単語) は繰り返されず、無視する必要があります。
まったく同じ順序で (one、two、three、four、five) のリストを取得したいと考えています。これをphpでどのように行うことができますか。私が今まで試したのは、単語の出現回数を数えることだけで、単語の順序を尊重しませんでした。
アップデート
皆さん回答ありがとうございます!
ここに私のコードがありますが、まだ多くのエラーがあります
<?php
$str = 'word
word
word2
word3
one
two
three
four
one
two
three
four
one
two
three
four
one
two
three
four
one
two
three
four
one
two
three
four
yes
no
do';
function repeated($str)
{
$str=trim($str);
$str=ereg_replace('[[:space:]]+', ' ',$str);
$words=explode(' ',$str);
$lastWord = '';
foreach($words as $w)
{
$wordstats[($w)]++;
if($lastWord!=''){
$wordstats[$lastWord.' '.$w]++;
}
$lastWord = $w;
}
foreach($wordstats as $k=>$v)
{
if($v>=2)
{
print "$k"." , ";
}
}
}
print repeated($str);
?>
基本的に私が望むのは、その中に単語 (one、two、three、four) が何度も繰り返される $str テキストを php に与え、パターン (one、two、three、four) を決定することです。