I am trying to write a function to filter a multidimensional associative array where the query array must match both with all keys and all values.
For example I need to filter this:
$data = array(
array("id"=>"1","color"=>"Red","size" => "L"),
array("id"=>"2","color"=>"Blue","size" => "L"),
array("id"=>"3","color"=>"Blue","size" => "L")
);
and the parameter I need to match are provided in an array like:
array("color"=>"Red","size" => "L")
So the I should get from the first array:
array("id"=>"1","color"=>"Red","size" => "L")
that is the only one that matches exactly all key names and values.
I have idea to iterate the array and to compare each value like:
$value['color'] == $query['color'] && $value['size'] == $query['size'] . . .
but I do not think is the best and i would like to write a more general function not with hardcoded array keys. How can I do?