Check if one of multiple values is included - PHP in_array()

How can I check if one or more of the multiple values are included in array() in PHP ?
posted on 12.06.2020 at 15:55
0pnshow more
onefiveonefive
Hi,

To check if at least one of the multiple values is included in PHP array, you can use this solution:

$first_array = array(1,2);
$second_array = array(1,3,5);

if ( array_intersect($first_array, $second_array) ) { echo "There is at least one match."; }
esle { echo "There is no match between arrays."; }

And to check if all of the multiple values are included in PHP array, you can use this solution:

$first_array = array(1,2,3);
$second_array = array(1,3,5,7);

if ( !array_diff($first_array, $second_array) ) { echo "All the values are included."; }
else { "Not all the values are included."; }


posted on 14.06.2020 at 17:23
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.