$array = ['red', 'orange'];
How can I check if this array contains only the values red
or orange
?
Thanks.
$array = ['red', 'orange'];
How can I check if this array contains only the values red
or orange
?
Thanks.
$array = ['red', 'orange'];
if (empty(array_diff($array, ['red', 'orange']))) {
echo "The array contains only red and orange.";
} else {
echo "The array contains other values besides red and orange.";
}
How about using array_diff() function to compare your array with an array that contains only the values "red" and "orange". If the result is an empty array, it means that your original array only contains those values.