0

I hope the title is descriptive, I am stuck so I am going to do my best to describe the issue.

I have a comparison I need to make for bed types on a search I am building. One is a $_POST array from the search form ($array1). It lists the bed types, so for example it would look something like:

array('King', 'Queen', 'Full');

My second array ($array2) is from my CMS's profile information and looks like this:

array(
"field_bed_types" => array(                
  "und" => array(
    "0" => array(
      "value" => "King"
            )

    "1" => array(
      "value" => "Double"
            )
        )
    )
)

The more bed types they have selected in their profile (there are 6) the more entries there would be past "1" in $array2.

What I am trying to achieve it to take the search types from $array1 and see if $array2 has all of the bed types listed in referenced in $array1. If not, I am doing a continue; and moving on to the next user profile record in my foreach loop.

In this example above, given that $array2 has only King and Double and $array1 is looking for a King, Queen and Full bed, the search should come back as FALSE and then continue to the next record. My question is, how do I do this?

I hope this makes sense, please let me know if you have any further questions.

Note: Drupal is the CMS in use here, but for all purposes this is still a multidimensional array, I just mention my CMS as a way to say that I don't have a way to change the data structure.

1
  • 1
    So can you show what you have done to this point so as to make this comparison? Do you have thoughts on how you might go about doing this? Commented Sep 19, 2013 at 18:08

1 Answer 1

1

Try this

foreach($array1 as $key=>$type)
{
    $return[$key]=false;
    foreach($array2['field_bed_types']['und'] as $typeArray)
    {
        if ($type==$typeArray['value'])
            $return[$key]=true;
    }
}
$failed=false;
foreach($return as $match)
{
    if($match==flase)
    {
        $failed=true;
    }
}
if($failed==false)
{
    // do stuff if passed
}
Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a champ. Thanks!
I took a second look at the code and it might give false positives. I have edited my answer so that it should yield better results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.