" . substr($word, 0, 1) . "" . substr($word, 1); } elseif ( $count == 4 ) { // If there are == 4 letters, two letters are bold. return "" . substr($word, 0, 2) . "" . substr($word, 2); } elseif ( $count > 4 ) { // If there are > 4 letters, 40% of all letters are bold. $ch = $count / 100 * 40; $c = (int)$ch; return "" . substr($word, 0, $c) . "" . substr($word, $c); } else { return $word; } } $output = array_map(function($word) { $word = preg_replace_callback('/\w+/i', 'style', $word); return $word; }, $arr); echo join($output, " "); ?>