<?php
function percentageSubStrings(array $inputs, array $needles): Generator
{
foreach($inputs as $input)
yield [$input => ((count($words = explode(' ', $input)) - count(array_diff($words, array_filter($needles, fn($x) => in_array($x, $words))))) / count($needles)) * 100];
}
var_dump(iterator_to_array(percentageSubStrings(['Some short text', 'Some much longer text'], ['Some', 'text', 'longer', 'much'])));
preferences:
23.8 ms | 409 KiB | 5 Q