= 2) { $mot = $ligne[0]; $definition = $ligne[1]; $dico[$mot] = $definition; } } fclose($handle); } $mots_de_n_lettres = [[]]; foreach ($dico as $mot => $definition) { $n = strlen($mot); if (!isset($mots_de_n_lettres[$n])) { $mots_de_n_lettres[$n] = []; } $mots_de_n_lettres[$n][] = $mot; } foreach ($mots_de_n_lettres as $n => $mots) { shuffle($mots_de_n_lettres[$n]); } function mots_espaces($max, $min=0) { global $mots_de_n_lettres; foreach($mots_de_n_lettres[$max] as $mot) { yield $mot; } for ($i = ceil($max / 2); $max - $i -1 >= $min; $i++) { foreach ($mots_de_n_lettres[$i] as $mot1) { foreach (mots_espaces($max - $i -1, $min) as $mot2) { if ($mot1 != $mot2) { yield "$mot1 $mot2"; yield "$mot2 $mot1"; } } } } }