Using string functions and a whole lot of if-else turns this into a real mess?
Converting strings to hex array might be another way?
It seems regex might have something do do with it?
Maybe one of the experts here can direct me to something that makes sense?
Possible $min and $max are always similar.
$min is a stored variable. $max is a client input.
Could be any character(s) [a-z, 0-9, A-Z]
Character(s) pair(s) seperated by single space.
Example: ‘p1’, ‘1 1’, ‘p1 h11’, ‘P3 h2’…
Result desired: ANY $max >= ANY $min
Examples:
$minA = 'p1 p2 h3'; $maxA = 'h2'; // false h2<=h3
$minB = '1 2 3'; $maxB = '4'; // true 4>=3
$minC = 'P2 p3'; $maxC = 'p2'; // true p2>=P2
$minD = 'p2 H33'; $max = 'p1 H34 y2'; // true H34>=H33
Here’s how it worked out — THANKS for the help
$min = 'p1 h3 t3';
$max = 'p1 h2';
echo ratingCheck($max, $min);
function ratingCheck($max, $min)
{
$minRank = strConv($min);
$maxRanks =strConv($max);
foreach ($maxRanks as $letter => $value)
{
echo ($value >= $minRank[$letter]) ? ' true ' : ' false ';
}
}
function strConv($str)
{
$exploded = explode(' ', $str);
foreach ($exploded as $rating)
{
preg_match('`([a-z]+)(\d+)`', $rating, $m);var_dump($m);
list(, $rating_letter, $rating_rank) = $m;
if (!isset($ratings[$rating_letter]))
{
$ratings[$rating_letter] = $rating_rank;
}
else
{
// for $min you should keep the highest value : max()
// for $max you should keep the lowest value : min()
$ratings[$rating_letter] = max($ratings[$rating_letter], $rating_rank);
}
}
return $ratings;
}
So based on what I understood.
You don’t care about case, start with putting everything in lower / upper case.
Split each $min and $max on ‘space character’.
explode(' ', 'p1 p2 h3') == array('p1', 'p2', 'h3);Store the lowest / higest rating for each letter in an array.
Recap at this point:
4- You then need to loop over $max to check if any rating is higher than any $min