Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created May 11, 2021 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobus1998/db37eb5961aa628b94f6d67ead7b75ed to your computer and use it in GitHub Desktop.
Save kobus1998/db37eb5961aa628b94f6d67ead7b75ed to your computer and use it in GitHub Desktop.
fuzzy finder test
<?php
$aPages = [
'reservation', 'room type', 'room', 'rate type', 'rate availability', 'settings', 'connectivity'
];
$aTests = [
'rs', 'rt', 'rm', 'rat', 'ra', 'st', 'cnn'
];
$aResults = [];
foreach ($aPages as $sPage) {
foreach ($aTests as $sTest) {
similar_text($sPage, $sTest, $fPerc);
$aResults[$sPage][$sTest] = $fPerc;
}
}
echo "\n";
foreach ($aResults as $sPage => $aResult) {
uasort($aResult, function ($a, $b) {
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
});
echo "{$sPage}\n";
foreach ($aResult as $sTest => $fPerc) {
echo "{$sTest}:\t{$fPerc}\n";
}
echo "\n";
}
echo "\n";
/*
results:
reservation
rat: 42.857142857143
rs: 30.769230769231
rt: 30.769230769231
ra: 30.769230769231
st: 30.769230769231
rm: 15.384615384615
cnn: 14.285714285714
room type
rt: 36.363636363636
rm: 36.363636363636
rat: 33.333333333333
rs: 18.181818181818
ra: 18.181818181818
st: 18.181818181818
cnn: 0
room
rm: 66.666666666667
rs: 33.333333333333
rt: 33.333333333333
ra: 33.333333333333
rat: 28.571428571429
st: 0
cnn: 0
rate type
rat: 50
rt: 36.363636363636
ra: 36.363636363636
rs: 18.181818181818
rm: 18.181818181818
st: 18.181818181818
cnn: 0
rate availability
rat: 30
rt: 21.052631578947
ra: 21.052631578947
rs: 10.526315789474
rm: 10.526315789474
st: 10.526315789474
cnn: 0
settings
st: 40
rs: 20
rt: 20
rat: 18.181818181818
cnn: 18.181818181818
rm: 0
ra: 0
connectivity
cnn: 40
rt: 14.285714285714
st: 14.285714285714
rat: 13.333333333333
rs: 0
rm: 0
ra: 0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment