3v4l.org

run code in 300+ PHP versions simultaneously
<?php $matches = [ [ 'insult' => [ 'text' => 'You fight like a Dairy Farmer!', 'maxDistance' => 15, ], 'response' => [ 'text' => 'How appropriate! You fight like a cow!', 'maxDistance' => 20, ], ], [ 'insult' => [ 'text' => 'This is the END for you, you gutter crawling cur!', 'maxDistance' => 32, ], 'response' => [ 'text' => 'And I\'ve got a little TIP for you, get the POINT?', 'maxDistance' => 25, ], ], ]; $search = "This is the end for you, gutter-crawling cur!"; $closestSet = null; $closestScore = 0; foreach ($matches as $set) { $score = similar_text($search, $set['insult']['text']); var_dump($score); if ($score > $closestScore) { $closestScore = $score; $closestSet = $set; } } echo "---", PHP_EOL; var_dump($search, $closestScore, $closestSet);

preferences:
31.67 ms | 405 KiB | 5 Q