php - Check if two pairs of values and keys exist in multidimensional
$permissions = array(
0 => array(
"action" => "CREATE",
"subject" => "USER"
),
1 => array(
"action" => "EDIT",
"subject" => "USER"
),
2 => array(
"action" => "DELETE",
"subject" => "USER"
),
3 => array(
"action" => "CREATE",
"subject" => "TASK"
),
);
I have this code to check if a combination between "key" and "value" there. Works perfectly.
public static function verifyPermissions($array, $key, $val) {
foreach ($array as $item){
if ( $item[$key] == $val)
return true;
}
return false;
}
The following line of code returns "TRUE", but there is no combination "action = EDIT" and "subject = TASK" in the same row of the array.
if(Group::verifyPermissions($permissions,"action","EDIT") && Group::verifyPermissions($permissions,"subject","TASK"))
I need to check these two options simultaneously, in the same row of the array. How do I fix this error?
Answer
Solution:
You can expand your function like this