$ra = new Regexp_Assemble(); foreach ($list as $p) { $ra->insert(str_split($p)); } $ra->_reduce(); is_deeply($ra->__path, ['t', ['' => 0, 'h' => ['h', ['' => 0, 'o' => ['o', 'r']]], 'r' => ['r']], 'o', 'u', 'g', 'h'], join(' ', $list)); $list = ['tough', 'though', 'trough', 'through', 'thorough']; $ra = new Regexp_Assemble(); foreach ($list as $p) { $ra->insert(str_split($p)); } $ra->_reduce(); is_deeply($ra->__path, ['t', ['' => 0, 'h' => ['h', ['o' => [['' => 0, 'o' => ['o', 'r']]], 'r' => ['r']]], 'r' => ['r']], 'o', 'u', 'g', 'h'], join(' ', $list)); $list = ['tit', 'titanate', 'titania', 'titanite', 'titano', 'tite', 'titi', 'titian', 'titien', 'tittie']; $ra = new Regexp_Assemble(); foreach ($list as $p) { $ra->insert(str_split($p)); } $ra->_reduce(); is_deeply($ra->__path, ['t', 'i', 't', ['' => 0, 'a' => ['a', 'n', ['a' => ['a', 't', 'e'], 'i' => ['i', ['a' => ['a'], 't' => ['t', 'e']]], 'o' => ['o']]], 'i' => ['i', ['' => 0, 'a' => [['e' => ['e'], 'a' => ['a']], 'n']]], 't' => [['' => 0, 't' => ['t', 'i']], 'e']]], join(' ', $list)); $ra = new Regexp_Assemble(); $ra->add('dasin'); $ra->add('dosin'); $ra->add('dastin'); $ra->add('dostin'); $ra->_reduce(); is_deeply($ra->__path, ['d', ['a' => ['a'], 'o' => ['o']], 's', ['' => 0, 't' => ['t']], 'i', 'n'], 'dasin/dosin/dastin/dosting'); /* is( $_, $fixed, '$_ has not been altered' ); */ echo "===OK===\n";