我想從給定的條件字典中刪除單詞。 我想這樣做,在下一次迭代時,字典將計算新的一個,最後一項刪除,所以它不會再計算。雙迴路去除物品
// sample data
$dict = ['aaa', 'aaan','aba', 'abat', 'ime', 'iso', 'nime', 'tiso',];
$unique = ['abatiso', 'aaanime'];
// could use while to further optimize unset (and remove on the fly) http://php.net/manual/en/control-structures.foreach.php#88578
while (list($key_word, $word) = each($unique)) { // $key is unused, just for the optimization that the whille provides
foreach ($dict as $key_other => $other) {
// ... conditions calculations
unset($unique[$key_word]);
}
}
echo "n compounds: " . count($compounds) . NL;
如果我設置內部循環而不是foreach作爲外部,我得到0結果,它立即終止。
現在,我得到重複的結果,如:
// Removed: abatiso => wc: aba + tiso = abatiso // Removed: abatiso => wc: abat + iso = abatiso // Removed: abatiso => wc: abati + so = abatiso // Removed: abatiso => wc: abatis + o = abatiso
我怎樣才能使它所以它刪除的話,不會對下一個迭代再次proccess呢?
一些測試數據:
Removed: aaaaaah => wc: aaaa + aah = aaaaaah
Removed: aaaaaah => wc: aaaaaa + h = aaaaaah
Removed: aaaaargh => wc: aaa + aargh = aaaaargh
Removed: aaaalead => wc: aaaa + lead = aaaalead
Removed: aaabbbccc => wc: aaab + bbccc = aaabbbccc
Removed: aaacomix => wc: aaa + comix = aaacomix
Removed: aaagak => wc: aaa + gak = aaagak
Removed: aaahh => wc: aaa + hh = aaahh
Removed: aaainc => wc: aaa + inc = aaainc
Removed: aaainc => wc: aaai + nc = aaainc
Removed: aaanet => wc: aaa + net = aaanet
Removed: aaanet => wc: aaan + et = aaanet
Removed: aaanime => wc: aaa + nime = aaanime
Removed: aaanime => wc: aaan + ime = aaanime
Removed: aaaron => wc: aaa + ron = aaaron
Removed: aabbcc => wc: aab + bcc = aabbcc
Removed: aabmup => wc: aab + mup = aabmup
Removed: aabre => wc: aab + re = aabre
Removed: aabybro => wc: aaby + bro = aabybro
Removed: aacap => wc: aac + ap = aacap
Removed: aacap => wc: aaca + p = aacap
Removed: aaccording => wc: aac + cording = aaccording
Removed: aacd => wc: aac + d = aacd
Removed: aachener => wc: aach + ener = aachener
Removed: aachener => wc: aachen + er = aachener
Removed: aacisuan => wc: aaci + suan = aacisuan
Removed: aacisuan => wc: aacis + uan = aacisuan
Removed: aacult => wc: aac + ult = aacult
我不使用內環內休息,因爲我必須做的計算也
。
請在您的問題和代碼更加具體。 – Eiko
@Eiko你不明白? – Cristo
我正在考慮類似於''for($ i = 0; $ i
Cristo