Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:08:06+00:00 2026-06-15T23:08:06+00:00

Using string functions and a whole lot of if-else turns this into a real

  • 0

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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:08:07+00:00Added an answer on June 15, 2026 at 11:08 pm

    So based on what I understood.

    1. You don’t care about case, start with putting everything in lower / upper case.

    2. Split each $min and $max on ‘space character’.

      explode(' ', 'p1 p2 h3') == array('p1', 'p2', 'h3);

    3. Store the lowest / higest rating for each letter in an array.

      $ratings = array();
      foreach ($exploded as $rating)
      {
          preg_match('`([a-z]+)(\d+)`', $rating, $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);
          }
      }
      

    Recap at this point:

    // If you had
    $min = 'p1 p2 h3';
    // Then you end up with an array like this:
    $minRanks = array(
        'p' => 2,
        'h' => 3,
    );
    
    
    // If you had
    $max = 'h2';
    // Then you end up with an array like this:
    $maxRanks = array(
        'h' => 2,
    );
    

    4- You then need to loop over $max to check if any rating is higher than any $min

    foreach ($maxRanks as $letter => $value)
    {
        if ($value >= $minRank[$letter])
        {
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem using some php functions on a string i get from
Assuming the input string +123-321+123 345 , using PHP's regex functions I would like
I am using this code to get data: Dim connetionString As String Dim connection
I have a problem using the string function erase with iterators. The function below
im new with regexp, so can i ask for some assistance Using string.replace function
I am saving an XMLDocument object to disk using the Save (string) function .
Has anybody got an idea of how to create a .Contains(string) function using Linq
I am having an issue removing %3Cbr+%2F%3E from my string using the preg_replace function.
original (update follows) I'm working with a lot of anonymous functions, ie functions declared
My JSF2 application is fully internationalized, using a ResourceBundle. Now i have a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.