<?php $names = array('A', 'B','R', 'R'); $output = ''; foreach ($names as $name) { similar_text($name, 'Roberto Smyth', $percent); $output .= "{$name} = {$percent}%\n"; } echo "<pre>{$output}</pre>"; ?>