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

  • SEARCH
  • Home
  • 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 8629935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:56:04+00:00 2026-06-12T08:56:04+00:00

I have been using this piece of code to compare two values, I am

  • 0

I have been using this piece of code to compare two values, I am getting the matched items exactly, The only problem is with non matched items.

$filter1 = "red,green,blue,yellow";         
$parts1 = explode(',', $filter1);

$filter2 = "red,green,blue";        
$parts2 = explode(',', $filter2);

for($i=0; $i< count($parts1); $i++)
{
  for($j=0; $j< count($parts2); $j++)
  {
    if(strpos($parts1[$i],$parts2[$j]) !== false)
    {
      $match[] = $parts1[$i];
    }
    else
    {
      $nomatch[] = $parts2[$j];
    }
  }
}

print_r($match);
echo "<br>";
print_r($nomatch);

And what i am getting as result is

Array ( [0] => red [1] => green [2] => blue ) 
Array ( [0] => green [1] => blue [2] => red [3] => blue [4] => red [5] => green [6] =>     
red [7] => green [8] => blue )

Array 1 is giving the exact matched values but array 2 is giving absurd results instead of yellow.

  • 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-12T08:56:05+00:00Added an answer on June 12, 2026 at 8:56 am

    Here you go:

    for($i=0; $i< count($parts1); $i++)
    {
      $matched = false;
      for($j=0; $j< count($parts2); $j++)
      {
        if(strpos($parts1[$i],$parts2[$j]) !== false)
        {
          $match[] = $parts1[$i];
          $matched = true;
          break;
        }
      }
      if (!$matched)
      {
        $nomatch[] = $parts1[$i];
      }
    }
    

    Demo: http://codepad.org/J6lmOUVO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have been using code similar to this in a piece of automation
I have been using this code to implement a Popup JDialog of sorts, like
I have been using this code, but have been running into some memory issues:
I have been using this code with great success to pull out the first
I have been using this as a reference, but not able to accomplish exactly
so I've been struggling with this piece of code for hours now, I have
I have two issues with this piece of code. I 'm having trouble because
I have been using a specific piece of code to delete files from a
I've been trying to parallelize this piece of code for about two days and
This is the piece of code that I am using. The ok(Object items) method

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.