I would like to check If a string has a similar_text percent value > 90%
This is my working code:
similar_text("maxmuster", "maxmustre", $percent);
if ( $percent > 90 ) {
echo 'Over 90% !';
}
Is there a way to create an one liner for that?
I tried something like this, which doesn't work:
if ( similar_text("maxmuster", "maxmustre", $percent) > 90 ) {
echo 'Over 90% !';
}
CodePudding user response:
if (similar_text("maxmuster", "maxmustre", $percent) && $percent > 90)
Note that this depends on the first part (similar_text("maxmuster", "maxmustre", $percent)
) returning a number > 0, otherwise it won't proceed to the second comparison. But in this case, if you require a percentage higher than 90 anyway, then the number of matching characters should also be greater than 0 anyway, so that shouldn't be an issue. Otherwise, the more complete code covering any case would be:
if ((similar_text("maxmuster", "maxmustre", $percent) || true) && $percent > 90)