I have the array and I want to check if there is any value from this array in my function.
Here is my code:
$values = [
'value_1',
'value_2',
'value_3'
];
if (has_block( any value from $values ) {
// stuff
}
So my point is: how to check if there is any value from array - maybe one, maybe all of them, without checking it by values itself like if (has_block( 'value_1') || has_block'value_2' )
?
I tried like this:
$values = [
'value_1',
'value_2',
'value_3'
];
$List = "'" . implode("', '", $values) . "'";
if (has_block( in_array($List, $values) ) ) {
// stuff
}
CodePudding user response:
if(isset($foo_array['somevalue']) || $foo_array['someothervalue'] === 'bla') {
// proceed
}
OR
if(in_array("avalue", $foo_array)) {
echo "Found It";
}
CodePudding user response:
Use array_intersect
. It will return new array with values that are in all arrays
$values = [
'value_1',
'value_2',
'value_3'
];
$search = [
'value_1',
'value_5',
];
if (!empty(array_intersect($search, $values))) {
// stuff
}