public static function printWords($words, $spaces = 8, $line = 80)
{
$ret = '';
foreach ($words as $type => $wordsByType) {
foreach ($wordsByType as $len => $wordsByLen) {
$count = round(($line - $spaces) / ($len + 9));
// strlen("'' => 1, ") = 9
$i = 0;
foreach ($wordsByLen as $word) {
if ($i == 0) {
$ret .= str_repeat(' ', $spaces);
}
$ret .= "'" . $word . "' => " . $type . ', ';
if (++$i == $count) {
$ret .= "\n";
$i = 0;
}
}
if ($i != 0) {
$ret .= "\n";
}
}
$ret .= "\n";
}
// Trim trailing spaces and return.
return str_replace(" \n", "\n", $ret);
}