jeudi 7 janvier 2016

Display best match first

$input = "work is hard";                    

if(preg_match(  "/(work|shift|useful)/i",$input)){
$match[]= "this is not better match";
}

if(preg_match(  "/(how|work|can|be|really|really|hard)/i",$input)){
$match[]= "this is better match";   // i want this match to appear first.
}

if i have multiple preg_match and one has more words that match the input, how can i make it so that it displays the one with the most matches. now, it just displays it in order. this is how it outputs

<?php
if(!empty($match)) {
foreach ($match as $r) {
    echo "<li>$r</li>\n";
        
}
}
?>

Aucun commentaire:

Enregistrer un commentaire