From a1e6d7773b2e177922a20fcd4d42b5d40e6a597d Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sun, 26 Sep 2021 19:25:07 +0200 Subject: [PATCH] Fix error in sorting a searched list by an inherent value --- src/MD_STD_SORT.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/MD_STD_SORT.php b/src/MD_STD_SORT.php index 44c5303..43e72a1 100644 --- a/src/MD_STD_SORT.php +++ b/src/MD_STD_SORT.php @@ -29,8 +29,14 @@ final class MD_STD_SORT { if ($a[$nameIndex] === $searchValue) return -1; if ($b[$nameIndex] === $searchValue) return 1; - if (stripos($a[$nameIndex], $searchValue) !== false) return -1; - if (stripos($b[$nameIndex], $searchValue) !== false) return 1; + $containsSearchA = stripos($a[$nameIndex], $searchValue); + $containsSearchB = stripos($b[$nameIndex], $searchValue); + + if ($containsSearchA !== false and $containsSearchB !== false) { + return $a[$sortIndex] > $b[$sortIndex] ? -1 : 1; + } + if ($containsSearchA !== false) return -1; + if ($containsSearchB !== false) return 1; return $a[$sortIndex] > $b[$sortIndex] ? -1 : 1; };