Reputation: 556
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.
Upvotes: 0
Views: 72
Reputation: 386
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
}
Upvotes: 1